“正则表达式 应用实例”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
| 第33行: | 第33行: | ||
</syntaxhighlight><syntaxhighlight lang="console"> | </syntaxhighlight><syntaxhighlight lang="console"> | ||
满足格式 | 满足格式 | ||
| + | </syntaxhighlight><syntaxhighlight lang="java"> | ||
| + | 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("不满足格式"); | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | </syntaxhighlight><syntaxhighlight lang="console"> | ||
| + | 不满足格式 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
2022年11月19日 (六) 06:42的版本
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("不满足格式");
}
}
}
不满足格式