| Summary: | java regex does not handle the Pattern.MULTILINE flag properly | ||
|---|---|---|---|
| Product: | [Fedora] Fedora | Reporter: | Lothar Grabowsky <lothar> |
| Component: | java-1.6.0-openjdk | Assignee: | Deepak Bhole <dbhole> |
| Status: | CLOSED NOTABUG | QA Contact: | Fedora Extras Quality Assurance <extras-qa> |
| Severity: | unspecified | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 13 | CC: | ahughes, dbhole, jvanek, langel, lkundrak, mjw, mmatejov, omajid |
| Target Milestone: | --- | ||
| Target Release: | --- | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Bug Fix | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2011-02-18 22:58:10 UTC | Type: | --- |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
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). |
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: