任何人都可以帮助使用正则表达式吗?这段代码工作得很好。
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");
}
}