I am new to regular expressions. I thought that this would return matched succesfully, but it does not. Why is that so?
String myString = "SUB_HEADER5_LABEL";
if (myString.matches(Pattern.quote("SUB_HEADER?_LABEL")))
{
System.out.println("matched succesfully");
}
Pattern.qoute()will create a Pattern that only matches exactly the given String. you needIf you expect the number to exceed 9, add the
+quantifier likeif you want to match a digit where you have
?(wich means one or zeroRin your case, because it’s a quantifier). you need to replace it with[0-9]or\\d.