正则表达式的用法 例子

 1 package cn.zmh.正则;
 2 
 3 public class RegexDemo {
 4     public static void main(String[] args) {
 5         checkMail();
 6         split_2();
 7         split_1();
 8     }
 9     //邮箱
10     public static void checkMail(){
11         String email = "15524562548@163.com";
12         boolean b = email.matches("[a-zA-Z0-9]+@[0-9a-z]+(\\.[a-z]+)+");
13         System.out.println(b);
14     }
15     //  19     89    12
16     public static void split_2(){
17         String st = "19  89  12";
18         String[] s = st.split(" ");
19         System.out.println("长度为"+s.length);
20         for(int i=0;i<s.length;i++){
21             System.out.println(s[i]);
22         }
23     }
24     // String split()
25     public static void split_1(){
26         String st = "2019-03-19-10-51";
27         //按照-对字符串进行切割
28         String[] stArr = st.split("-");
29         System.out.println("长度为:"+stArr.length);
30         for(int i=0;i<stArr.length;i++){
31             System.out.println(stArr[i]);
32         }
33     }
34 }

 

posted @ 2019-03-19 23:19  Java练习生  阅读(219)  评论(0编辑  收藏  举报