我有以下文件内容,我正在尝试匹配下面解释的 reg:
-- file.txt (doesn't match multi-line) --
test
On blah
more blah wrote:
---------------
如果我将文件内容从上面读取到字符串并尝试匹配“On...wrote:”部分,我无法得到匹配:
// String text = <file contents from above>
Pattern PATTERN = Pattern.compile("^(On\\s(.+)wrote:)$", Pattern.MULTILINE);
Matcher m = PATTERN.matcher(text);
if (m.find()) {
System.out.println("Never gets HERE???");
}
如果文件的内容在一行上,则上述正则表达式可以正常工作:
-- file2.txt (matches on single line) --
test
On blah more blah wrote: On blah more blah wrote:
---------------
如何让多行工作和单行都在一个正则表达式中(或两个)?谢谢!