目录

正则表达式,idea,插件anyrule

目录

正则表达式,idea,插件anyrule

https://i-blog.csdnimg.cn/direct/c19a0962d37b40ae8db4012c4ad947dc.png

![](https://i-blog.csdnimg.cn/direct/b9355e86d31f4f75886dd8a702d771ec.jpeg)

https://i-blog.csdnimg.cn/direct/b89771f0e32d4d6095a5aa7534b8cc0f.jpeg

​​​​package lx;
import java.util.regex.Pattern;
public class lxx {
public static void main(String[] args) {
//正则表达式
//写一个电话号码的正则表达式
String regex = "1[3-9]\\d{9}";//第一个数字是1,第二个数字是3-9,后面跟着9个数字
boolean f = Pattern.matches(regex, "1,2,3,4,5,6,7,8,9");
System.out.println("1,2,3,4,5,6,7,8,9,4".matches(regex));
System.out.println(f);
//座机电话号码正则表达式
// 0712-3242434
String regex2 = "0\\d{2,3}-?\\d{4,9}";
//第一个为0,第二个为2-3个数字,第三个为-或者没有,第四个为4-9个数字
//邮箱正则表达式
//dlei0009@pci.com.cn
String regex3 = "\\w+@[\\w&&[^_]]{2,6}(\[a-zA-Z]{2,3}){1,2}";
boolean f2 = Pattern.matches(regex2, "1,2,3,4,5,6,7,8,9");
System.out.println("1,2,3,4,5,6,7,8,9,4".matches(regex3));
System.out.println(f2);
//第一个任意字母下滑线至少出现一次,第二个必须是@,第三个任意字母除下滑线,第四个必须是.,第五个任意字母2到3个
//()内的分成一组,后面的{1,2}表示这个组出现1到2次
String s="[1-9]\\d{16}(\\d|X|x)";
// "[1-9]\\d{16}(\\d|Xx)";
String s2= "[1-9]\\d{5}(?:18|19|20)\\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\\d|30|31)\\d{3}[\\dXx]";
System.out.println("341302200211122343".matches(s2));
//忽略大小写
String regex4 = "(?i)abc";//会忽略abc大小写
String regex5 = "ABC";
///11? System.out.println(regex5.matches(regex4));
}
}