次のファイルの内容があり、以下で説明する 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???");
}
ファイルの内容が 1 行にある場合、上記の正規表現は正常に機能します。
-- file2.txt (matches on single line) --
test
On blah more blah wrote: On blah more blah wrote:
---------------
複数行を機能させ、単一行をすべて1つの正規表現(または2つ)にするにはどうすればよいですか? どうも!