2016-02-16 103 views
0

我有一个正则表达式命令的问题:用正则表达式分隔符

text="blue: 
allocatable 
allocate 
assign" //it has delimiters (new lines) 

String patternblue = ".*blue.*"; 
boolean isMatchblue = Pattern.matches(patternblue, text.toString()); 
System.out.println(isMatchblue); 

给人“假”,会发生什么?

我检查了论坛上的其他帖子,但我没有得到它的工作与。*?也不?的

回答

3

对于这个特定的Pattern,您需要使用DOTALL标志,作为.*blue不会换行,否则匹配。

由于没有matches重写需要可选的标志,你可能最终会改变你的代码:

Pattern.compile(patternblue, Pattern.DOTALL).matcher(text).matches();