A DESCRIPTION OF THE PROBLEM :
The Javadoc for Pattern does not document the fact that $ (not in MULTILINE mode) will not only match at the very end of the input-sequence, but also right before a final line-terminator in the input-sequence.
Currently, the Javadocs say "By default, the regular expressions ^ and $ ignore line terminators and only match at the beginning and the end, respectively, of the entire input sequence."
But the following Code produces two matches, due to behavior apparently inherited from Perl:
---
var m = Pattern.compile("\n\\z").matcher("\n\n");
while (m.find()) {
System.out.println(m.start() + ":" + m.end());
}
---
Internally, this behavior is documented in the Javadoc for the "Pattern.Dollar" inner-class:
"When not in multiline mode, the $ can only match at the very end
of the input, unless the input ends in a line terminator in which
it matches right before the last line terminator."
This should be reflected in the public Javadoc as well.
FREQUENCY : always
The Javadoc for Pattern does not document the fact that $ (not in MULTILINE mode) will not only match at the very end of the input-sequence, but also right before a final line-terminator in the input-sequence.
Currently, the Javadocs say "By default, the regular expressions ^ and $ ignore line terminators and only match at the beginning and the end, respectively, of the entire input sequence."
But the following Code produces two matches, due to behavior apparently inherited from Perl:
---
var m = Pattern.compile("\n\\z").matcher("\n\n");
while (m.find()) {
System.out.println(m.start() + ":" + m.end());
}
---
Internally, this behavior is documented in the Javadoc for the "Pattern.Dollar" inner-class:
"When not in multiline mode, the $ can only match at the very end
of the input, unless the input ends in a line terminator in which
it matches right before the last line terminator."
This should be reflected in the public Javadoc as well.
FREQUENCY : always
- csr for
-
JDK-8296529 Document the default behavior of '$' in regular expressions correctly
-
- Closed
-
- duplicates
-
JDK-8059325 The documentation of regex $ is still wrong
-
- Closed
-
-
JDK-8183391 Regex: End of line found more than once for non-multiline regex
-
- Closed
-
-
JDK-8218146 $ matches before end of line, even without MULTILINE mode
-
- Closed
-
(1 links to)