Matching Line Boundaries in a Regular Expression (Pattern.MULTILINE/(?m)) is broken in Java?
- by Mister M. Bean
The example on http://www.exampledepot.com/egs/java.util.regex/Line.html gives false for me twice but should'nt! Why?
CharSequence inputStr = "abc\ndef";
String patternStr = "abc$";
// Compile with multiline enabled
Pattern pattern = Pattern.compile(patternStr, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(inputStr);
boolean matchFound = matcher.find(); // true
// Use an inline modifier to enable multiline mode
matchFound = pattern.matches(".*abc$.*", "abc\r\ndef"); // false
System.out.println(matchFound); // false
matchFound = pattern.matches("(?m).*abc$.*", "abc\r\ndef"); // true
System.out.println(matchFound);// false !!!!!