2016-02-16 104 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();