1、要匹配手机号如13xxx,15xxx,18xxx代码如下
String tel = “13xxxxxxxxx;”
String telReg = “1[358]\d{9}”;
判断boolean flag = tel.matches(telReg);是则返回true否则返回false
2、要切割字符串如String str = “dsljeig.asjgioja.asgwgh”;
则匹配的字符串是String reg = “\.”;
切割字符串是String [] arr = str.split(reg);
for(String s:arr){
String str = s;
}
3、匹配空格String str = “asetg awetgw4g erywyh”;
匹配规则:String reg = ” +”;
判断是否匹配:str.matches(reg);
4、匹配String str = “c:adf\ag\a.txt”;
String reg = “[url=]\\[/url]”;
String[] arr = str..split(reg);
5、按照叠词进行切割
当你想对一个结果重用是你可以把它封装成一个组
String str = “qwdddqaweeeeeeeaeggdsegsdgsssfewghws”;
String reg = “(.)\1+”;//(.)代表任意字符1+代表多个相同的字符(叠词)
String [] arr = str.split(reg);
6、正则表达式(获取)
String str = “ming tian jiu yao fang jia le, shi