I am trying to match a character e.g. ‘ if it doesn’t have the character \ before it.
Valid État de l\'impression
Invalid État de l'impression
Valid Saisir l\'utilisateur et le domaine pour la connexion
I believe what I am after is sort of assertion such as a negative lookbehind?
e.g. (?<!\\)' which works fine when I am testing in RegexBuilder
However the problem is when I am trying to make this work in Java
Code
String[] inputs = new String[] { "Recherche d'imprimantes en cours…", "Recherche d\\'imprimantes en cours…" } ;
for(String input : inputs)
{
Pattern p = Pattern.compile("(?<!\\\\)'");
System.out.println(input);
System.out.println(p.matcher(input).matches());
}
Output
Recherche d'imprimantes en cours…
false
Recherche d\'imprimantes en cours…
false
Which should match true, false
p.matcher(input).matches()validates the entire input. Tryp.matcher(input).find()instead.