-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 16
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
java.util.regex.Matcher#replaceAll(java.lang.String) gives wrong result for the regular expression .*
Code:
result = Pattern.compile(".*").matcher("test").replaceAll("X");
Expected Result: "X"
Actual Result: "XX"
The first occurrence of the replacement string stems from the expected match of the whole input "test".
The second replacement string stems from an additional match of the empty string at the end of the input. This match should not occur.
The pattern ".*$" does not prevent the additional match.
---------- BEGIN SOURCE ----------
result = Pattern.compile(".*").matcher("test").replaceAll("X");
assertEquals("X", result);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use the pattern "^.*" instead of " .*"
FREQUENCY : always
java.util.regex.Matcher#replaceAll(java.lang.String) gives wrong result for the regular expression .*
Code:
result = Pattern.compile(".*").matcher("test").replaceAll("X");
Expected Result: "X"
Actual Result: "XX"
The first occurrence of the replacement string stems from the expected match of the whole input "test".
The second replacement string stems from an additional match of the empty string at the end of the input. This match should not occur.
The pattern ".*$" does not prevent the additional match.
---------- BEGIN SOURCE ----------
result = Pattern.compile(".*").matcher("test").replaceAll("X");
assertEquals("X", result);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use the pattern "^.*" instead of " .*"
FREQUENCY : always