“正则表达式 应用实例”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) (建立内容为“https://www.bilibili.com/video/BV1Eq4y1E79W/?p=16”的新页面) |
Jihongchang(讨论 | 贡献) |
||
| 第1行: | 第1行: | ||
https://www.bilibili.com/video/BV1Eq4y1E79W/?p=16 | https://www.bilibili.com/video/BV1Eq4y1E79W/?p=16 | ||
| + | |||
| + | === 示例:验证是不是汉字 === | ||
| + | <syntaxhighlight lang="java"> | ||
| + | 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("不满足格式"); | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | </syntaxhighlight><syntaxhighlight lang="console"> | ||
| + | 满足格式 | ||
| + | </syntaxhighlight> | ||
2022年11月19日 (六) 06:41的版本
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("不满足格式");
}
}
}
满足格式