Skip to content

Commit c61d6e2

Browse files
committed
hw for section20
1 parent 16ad986 commit c61d6e2

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package homework.section20;
2+
3+
public class CheckEmail {
4+
5+
public static void main(String[] args) {
6+
String email = "zsy@sina.com";
7+
String regex = "^\\w+@\\w+(\\.[a-zA-Z]{2,3}){1,2}$";
8+
System.out.println(email.matches(regex));
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package homework.section20;
2+
3+
import java.util.regex.Matcher;
4+
import java.util.regex.Pattern;
5+
6+
public class CheckPhoneNumber {
7+
8+
public static void main(String[] args) {
9+
Pattern pattern = Pattern.compile("^\\d{11}$", Pattern.CASE_INSENSITIVE);
10+
Matcher matcher = pattern.matcher("18637866964");
11+
System.out.println(matcher.find());
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package homework.section20;
2+
3+
4+
public class RemoveDuplicate {
5+
6+
public static void main(String[] args) {
7+
String str = "我我我、、、我我、、我要、我要要、、、要要要、、要要、、学学学、、、、学学编、、、学编编编、、编编编程、、程程";
8+
str = str.replaceAll("(、+)", "");
9+
str = str.replaceAll("(.)\\1+", "$1");
10+
System.out.print(str); // 我要我要学编学编程
11+
}
12+
}

0 commit comments

Comments
 (0)