我有以下的(Java)的代碼:Java的正則表達式混亂
public class TestBlah {
private static final String PATTERN = ".*\\$\\{[.a-zA-Z0-9]+\\}.*";
public static void main(String[] s) throws IOException {
String st = "foo ${bar}\n";
System.out.println(st.matches(PATTERN));
System.out.println(Pattern.compile(PATTERN).matcher(st).find());
System.exit(0);
}
}
運行這段代碼,前者System.out.println
輸出false
,而後者輸出true
難道我不是在這裏瞭解些什麼呢?
從同一個文檔:正則表達式。匹配除行結束符之外的任何字符,除非指定了DOTALL標誌。 – gawi 2010-09-08 20:31:43