-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8u20
-
x86
-
windows_8
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 8 x64, Windows 7 x64 -- neither works, since it is likely not an OS-specific issue.
A DESCRIPTION OF THE PROBLEM :
When using the word boundary \b on the right of an escaped period \., the regex fails to match. If a instead alphabetical character is the last character before the escaped period, it matches without issue. I can't account for this behavior since the escaped period should act just like any other character literal.
So for example:
"ab." would match regex "ab\."
but
"ab." would not match regex "ab\.\b"
yet:
"ab.c" would match regex "ab\.c\b"
It appears that the escaped period is being treated specially when it should not. There may be other special characters that have this strange behavior.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please run the program provided and examine the output.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Once a period is escaped, it should behave identically to an other character literal such as "abc".
ACTUAL -
The escaped period does not match when a \b qualifier is present.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.regex.Pattern;
public class JavaRegexBug {
public static void main(String[] args) {
String[] regexPatterns = new String[] {
"ab\\.", //Works
"\\bab\\.", //Works
"\\bab\\.\\b", //Does not work
"(ab\\.)", //Works
"\\b(ab\\.)", //Works
"\\b(ab\\.)\\b", //Does not work
"ab\\.c", //Works
"(ab\\.c)", //Works
"\\b(ab\\.c)", //Works
"\\b(ab\\.c)\\b" //Works
};
String strings[] = new String[] {
"ab.",
"ab.",
"ab.",
"ab.",
"ab.",
"ab.",
"ab.c",
"ab.c",
"ab.c",
"ab.c"
};
for(int i=0; i<regexPatterns.length; i++) {
Pattern p = Pattern.compile(regexPatterns[i]);
String s = strings[i];
System.out.printf("Regex %12s ~= %s\t- ", regexPatterns[i], s);
if(p.matcher(s).matches()) {
System.out.println("matches.");
} else {
System.out.println("does not match!");
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None so far.
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 8 x64, Windows 7 x64 -- neither works, since it is likely not an OS-specific issue.
A DESCRIPTION OF THE PROBLEM :
When using the word boundary \b on the right of an escaped period \., the regex fails to match. If a instead alphabetical character is the last character before the escaped period, it matches without issue. I can't account for this behavior since the escaped period should act just like any other character literal.
So for example:
"ab." would match regex "ab\."
but
"ab." would not match regex "ab\.\b"
yet:
"ab.c" would match regex "ab\.c\b"
It appears that the escaped period is being treated specially when it should not. There may be other special characters that have this strange behavior.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please run the program provided and examine the output.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Once a period is escaped, it should behave identically to an other character literal such as "abc".
ACTUAL -
The escaped period does not match when a \b qualifier is present.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.regex.Pattern;
public class JavaRegexBug {
public static void main(String[] args) {
String[] regexPatterns = new String[] {
"ab\\.", //Works
"\\bab\\.", //Works
"\\bab\\.\\b", //Does not work
"(ab\\.)", //Works
"\\b(ab\\.)", //Works
"\\b(ab\\.)\\b", //Does not work
"ab\\.c", //Works
"(ab\\.c)", //Works
"\\b(ab\\.c)", //Works
"\\b(ab\\.c)\\b" //Works
};
String strings[] = new String[] {
"ab.",
"ab.",
"ab.",
"ab.",
"ab.",
"ab.",
"ab.c",
"ab.c",
"ab.c",
"ab.c"
};
for(int i=0; i<regexPatterns.length; i++) {
Pattern p = Pattern.compile(regexPatterns[i]);
String s = strings[i];
System.out.printf("Regex %12s ~= %s\t- ", regexPatterns[i], s);
if(p.matcher(s).matches()) {
System.out.println("matches.");
} else {
System.out.println("does not match!");
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None so far.