1、校验数字表达式
1. 数字:^[0-9]*$
2. n位的数字:^\d{n}$
3. 至少n位的数字:^\d{n,}$
4. m-n位的数字:^\d{m,n}$
2、校验字符表达式
1. 汉字:^[\u4e00-\u9fa5]{0,}$
3、特殊需求的表达式
1.中文字符的正则表达式:[\u4e00-\u9fa5]
2.中国邮政编码:[1-9]\d{5}(?!\d) (中国邮政编码为6位数字)
3.Email地址:^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
4.国内电话号码(0511-4405222、021-87888822):d{3}-\d{8}|\d{4}-\d{7} ^0[1-9]{2,3}-[1-9][0-9]{7,8}
5.身份证号(15位、18位数字):^\d{15}|\d{18}$
6.日期格式:^\d{4}-\d{1,2}-\d{1,2}
参考: https://blog.csdn.net/ZYC88888/article/details/98479629
https://www.runoob.com/regexp/regexp-tutorial.html
https://www.jianshu.com/p/a4f7a17be4ef
在线测试工具: http://c.runoob.com/front-end/854
附:正则里的 .*? 是什么意思?
. 是任意字符 可以匹配任何单bai个字符,
例子du:正则表达式r.t 可以匹配这些字符串:rat、zhirut、r t,但是不匹配root。
.*? 表示匹配任意字符到下一个符合条件的字符
.*? 表示匹配任意数量的重复,但是在能使整个匹配成功的前提下使用最少的重复。为非贪婪匹配模式
例子:正则表达式a.*?xxx 可以匹配 abxxx axxxxx abbbbbxxx