Hide Forgot
Description of problem: java regex does not handle the Pattern.MULTILINE flag properly. Version-Release number of selected component (if applicable): 1.6.0.0-50.1.8.7 How reproducible: According to the documentation of the MULTILINE flag the pattern "^a.*b$" should match the string "xy\naxb" when the MULTILINE flag is set, because ^ should match the start of the second line in this case (i.e. the position after '\n'). Thus the given input obviously matches the specified pattern. Steps to Reproduce: 1. The following little test program can be used to reproduce the issue: import java.util.regex.Pattern; import java.util.regex.Matcher; public class RegexTest { public static void main(String[] argv) { Pattern pat = Pattern.compile("^a.*b$", Pattern.MULTILINE); Matcher match = pat.matcher("xy\naxb"); if (match.matches()) { System.out.println("match OK"); System.exit(0); } else { System.out.println("match FAILED"); System.exit(1); } } } ~ Actual results: The expression does not match. Expected results: The expression should match. Additional info:
Matcher.matches() attempts to match the entire sequence. What you need in the if condition is match.find() instead of match.matches(). With match.find(), the pattern matches correctly (and conversely, fails if Pattern.MULTILINE is removed).