public class test {
public static void main(String[]args) {
String test1 = "Nørrebro, Denmark";
String test2 = "ø";
String regex = new String("^&\\S*;$");
String value = test1.replaceAll(regex,"");
System.out.println(test2.matches(regex));
System.out.println(value);
}
}
This gives me following Output:
true
Nørrebro, Denmark
How is that possible ? Why does replaceAll() not register a match?
valuecomes from replacing test1, while yourmatchesis testing test2.test2matches with regex.test1does not.test2matches the regex, but only if it's a whole string and not a substring. Check what$means at the end of a regex...