Skip to content

Commit b32868a

Browse files
author
shy-coder
committed
daily14:正则表达式学习(邮箱,手机号)
1 parent 6d17a24 commit b32868a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.shy.day14;
2+
3+
import java.util.regex.Matcher;
4+
import java.util.regex.Pattern;
5+
6+
/**
7+
* @ClassName test1
8+
* @Author shy
9+
* @Date 2020/11/2
10+
**/
11+
public class test1 {
12+
public static void main(String[] args) {
13+
String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
14+
Pattern regex = Pattern.compile(check);
15+
Matcher matcher = regex.matcher("2437309168@qq.1cn");
16+
boolean isMatched = matcher.matches();
17+
System.out.println(isMatched);
18+
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.shy.day14;
2+
3+
import java.util.regex.Matcher;
4+
import java.util.regex.Pattern;
5+
6+
/**
7+
* @ClassName test2
8+
* @Author shy
9+
* @Date 2020/11/2
10+
**/
11+
public class test2 {
12+
public static void main(String[] args) {
13+
String check = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
14+
Pattern regex = Pattern.compile(check);
15+
Matcher matcher = regex.matcher("03174154204");
16+
System.out.println(matcher.matches());
17+
}
18+
}

0 commit comments

Comments
 (0)