Matching Line Boundaries in a Regular Expression (Pattern.MULTILINE/(?m)) is broken in Java?

Posted by Mister M. Bean on Stack Overflow See other posts from Stack Overflow or by Mister M. Bean
Published on 2010-04-25T08:34:32Z Indexed on 2010/04/25 8:43 UTC
Read the original article Hit count: 205

Filed under:
|

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 !!!!!

© Stack Overflow or respective owner

Related posts about java

Related posts about pattern