我有以下的(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