2018-10-31
作者:
单是一个姓 | 来源:发表于
2018-10-31 20:59 被阅读0次
java正则表达式常用一般是:
- 全局匹配字符串 Pattern.compile(“”).matcher("").matchers()
- 循环根据子串循环查找匹配 Pattern.compile("").find()
String str = "遇到数字1就被匹配,2也是";
String regEx = "\\d+";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(str);
// 循环局域匹配
while (matcher.find()) {
String s = matcher.group(); // 返回与上一个匹配匹配的输入子序列
System.out.println(s); // 1 2
}
// 尝试将整个区域与模式进行匹配。
System.out.println(pattern.matcher("234242").matches()); // true
System.out.println("123".matches(regEx)); // true 是否匹配指定的字符串
常用正则表达式(最新——戒指2018-10-31):
- 身份证号正则
"(^[1-9][0-9]{5}(18|19|([23][0-9]))[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{3}[0-9Xx]
)"
- 日期正则
"(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)"
- 字母正则
"[a-zA-Z]"
- 金额正则
"^\d{1,8}(\.\d{1,2})?$"
- 金额正则模式
"^\d{1,8}(\.\d{1,2})?$"
- 图片文件名正则
"(.bmp)|(.jpg)|(.gif)|(.png)$"
- 成绩分数正则
"^(([1-9]?[0-9])|100)(.[0-9])?$"
推荐正则语法规则资料
本文标题:2018-10-31
本文链接:https://www.haomeiwen.com/subject/agdztqtx.html
网友评论