以下方法环境为Java语言
字符串是否包含数字:
"gfdgd1111".matches("[^.]*[\\d]+[^.]*")
炸弹号码666..或888...或999...:
String str = "";
String pattern = "^(6+|8+|9+)$";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(str);
System.out.println(m.matches());
本文介绍了使用Java正则表达式进行字符串匹配的方法,包括检查字符串是否包含数字以及判断字符串是否为炸弹号码(如连续的6、8或9)。通过具体代码示例,读者可以学习如何利用Pattern和Matcher类实现这些功能。
字符串是否包含数字:
"gfdgd1111".matches("[^.]*[\\d]+[^.]*")
炸弹号码666..或888...或999...:
String str = "";
String pattern = "^(6+|8+|9+)$";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(str);
System.out.println(m.matches());
4万+
1万+
4337
6567
2万+
1万+

被折叠的 条评论
为什么被折叠?