第一种匹配方式
import java.util.regex.*;
public class RegexExample1{
public static void main(String args[]){
String content = "需要校验的内容";
String pattern = "正则表达式";
boolean isMatch = Pattern.matches(pattern, content);
System.out.println(isMatch);
}
}
第二种匹配方式
import java.util.regex.*;
public class RegexExample1{
public static void main(String args[]){
String content = "需要校验的内容";
String pattern = "正则表达式";
Pattern p = Pattern.compile(pattern );
Matcher m = p.matcher(content);
System.out.println(m.matches());
}
}