Any idea why this Java test case fails?
@Test
public void newlineParse() throws Exception {
Pattern pat = Pattern.compile("a.*b", Pattern.MULTILINE);
assertTrue(pat.matcher("a\nb").find());
}
Any idea why this Java test case fails?
@Test
public void newlineParse() throws Exception {
Pattern pat = Pattern.compile("a.*b", Pattern.MULTILINE);
assertTrue(pat.matcher("a\nb").find());
}
I believe the issue is that the Pattern.MULTILNE
is incorrect. For the particular example, it should be Pattern.DOTALL
(or embed the ?s in the expression).
Enables multiline mode.
In multiline mode the expressions ^ and $ match just after or just before, respectively, a line terminator or the end of the input sequence. By default these expressions only match at the beginning and the end of the entire input sequence.
Multiline mode can also be enabled via the embedded flag expression (?m).
In dotall mode, the expression . matches any character, including a line terminator. By default this expression does not match line terminators.