使用正则表达式匹配多行文本
PatternPattern.MULTILINE(?m).
(?m)String.matches
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?
汪汪一只猫
三国纷争
随时随地看视频慕课网APP
相关分类