正则表达式 应用实例
https://www.bilibili.com/video/BV1Eq4y1E79W/?p=16
示例:验证是不是汉字
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegExp10 {
public static void main(String[] args) {
String content = "韩顺平教育";
String regStr = "^[\u0391-\uffe5]+$";
Pattern pattern = Pattern.compile(regStr);
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
System.out.println("满足格式");
} else {
System.out.println("不满足格式");
}
}
}
满足格式
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegExp10 {
public static void main(String[] args) {
String content = "韩顺平a教育";
String regStr = "^[\u0391-\uffe5]+$";
Pattern pattern = Pattern.compile(regStr);
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
System.out.println("满足格式");
} else {
System.out.println("不满足格式");
}
}
}
不满足格式