KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to match a multi line text using Java. When I use the Pattern class with the Pattern.MULTILINE modifier, I am able to match, but I am not able to do so with (?m). The same pattern with (?m) and using String.matches does not seem to work. I am sure I am missing something, but no idea what. This is what I tried: String test = "User Comments: This is \t a\ta \n test \n\n message \n"; String pattern1 = "User Comments: (\\W)*(\\S)*"; Pattern p = Pattern.compile(pattern1, Pattern.MULTILINE); System.out.println(p.matcher(test).find()); //true String pattern2 = "(?m)User Comments: (\\W)*(\\S)*"; System.out.println(test.matches(pattern2)); //false - why?
Tags (comma-separated)
Save Edits
Cancel