1 import java.util.regex.*;
2 public class Demo
3 {
4 public static void main(String[]args){
5 //1、正则验证Email
6 String email="XXXX@.163.com";
7 Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
8 Matcher m = p.matcher(email);
9 if(m.matches()){
10 System.out.println("有效的邮件地址");
11 }else{
12 System.out.println("无效的邮件地址");
13 }
14
15 //2、反转字符串,有小写字母就转换成大写
16 String str="abc123";
17 String[]arrs=str.split("");
18 for(int i=arrs.length-1;i>=0;i--){
19 System.out.print(arrs[i].toUpperCase()+" ");
20 }
21 System.out.println();
22 //3、使用regex来检索,替换字符串中的逗号
23 String s="asdm,y,e,wwer,wer";
24 Pattern p1 = Pattern.compile("[a-z]");
25 Matcher m1 = null;
26 String[]arr=s.split("");
27 for(int i=0;i<arr.length;i++){
28 m1 = p1.matcher(arr[i]);
29 if(m1.matches()){
30 System.out.print(arr[i]);
31 }
32
33 }
34
35 }
36 }