任何人都可以幫助正則表達式嗎?此代碼工作良好。Java正則表達式。奇怪的行爲
public static void main(String[] args) {
String s = "with name=successfully already exist\n";
Pattern p = Pattern.compile(".+name=.*successfully.+", Pattern.DOTALL);
java.util.regex.Matcher m = p.matcher(s);
if (m.matches()) {
System.out.println("match");
} else {
System.out.println("not match");
}
}
但此代碼返回「不匹配」。爲什麼?
public static void main(String[] args) {
String s = "with name=successfully already exist\n";
if (s.matches(".+name=.*successfully.+")) {
System.out.println("match");
} else {
System.out.println("not match");
}
}