Java 正则表达式不匹配多行字符串

Java regex does not match multiline string

对不起,我是 Java 的新人。我需要匹配 Java 中的多行字符串,它看起来像:

meno je povinné pole
priezvisko je povinné pole
heslo je povinné pole
email je povinné pole
email nemá platný formát
musíte súhlasiť s podmienkami

这是匹配该字符串的模式。

Pattern p = Pattern.compile("meno.+heslo", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.MULTILINE);
Matcher m = p.matcher(alert.getText().toLowerCase());  // text from the example

这有什么问题?如果我只测试第一行,它就可以工作。所以我认为问题出在线路上。

. 将不匹配换行符,要修复此问题,请在编译模式时使用 DOTALL 标志。

 Pattern.DOTALL

MULTILINE 标志只会执行以下操作:

"In multiline mode the expressions ^ and $ match just after or just before, respectively, a line terminator or the end of the input sequence."