ADDITIONAL SYSTEM INFORMATION :
Linux x64 based. tested with Java 11 and freshly downloaded jdk-18
A DESCRIPTION OF THE PROBLEM :
Regex Pattern.matches(REGEX, STRING) Failes to match \b boundry
Pattern.compile(REGEX).matcher(STRING) works as expected
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
just using \b at the end of a regex from Pattern.matches() function.
if (Pattern.matches("HI\\b", "HI hi")) {
System.out.println("I will not match properly");
}
if (Pattern.matches("HI\\b", "HI")) {
System.out.println("I will match");
}
if (Pattern.compile("HI\\b").matcher("HI hi").find()) {
System.out.println("I will match from compiled");
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I will not match properly
I will match
I will match from compiled
ACTUAL -
I will match
I will match from compiled
---------- BEGIN SOURCE ----------
if (Pattern.matches("HI\\b", "HI hi")) {
System.out.println("I will not match properly");
}
if (Pattern.matches("HI\\b", "HI")) {
System.out.println("I will match");
}
if (Pattern.compile("HI\\b").matcher("HI hi").find()) {
System.out.println("I will match from compiled");
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use patther.compile pattern.
FREQUENCY : always
Linux x64 based. tested with Java 11 and freshly downloaded jdk-18
A DESCRIPTION OF THE PROBLEM :
Regex Pattern.matches(REGEX, STRING) Failes to match \b boundry
Pattern.compile(REGEX).matcher(STRING) works as expected
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
just using \b at the end of a regex from Pattern.matches() function.
if (Pattern.matches("HI\\b", "HI hi")) {
System.out.println("I will not match properly");
}
if (Pattern.matches("HI\\b", "HI")) {
System.out.println("I will match");
}
if (Pattern.compile("HI\\b").matcher("HI hi").find()) {
System.out.println("I will match from compiled");
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I will not match properly
I will match
I will match from compiled
ACTUAL -
I will match
I will match from compiled
---------- BEGIN SOURCE ----------
if (Pattern.matches("HI\\b", "HI hi")) {
System.out.println("I will not match properly");
}
if (Pattern.matches("HI\\b", "HI")) {
System.out.println("I will match");
}
if (Pattern.compile("HI\\b").matcher("HI hi").find()) {
System.out.println("I will match from compiled");
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use patther.compile pattern.
FREQUENCY : always