万能的正则

1.分析URL正则

(?[a-z]{2,6}):\/\/((?[a-z0-9]{0,10}\.{1}){0,2}(?[a-z\-0-9]{1,30}){1}\.{1}(?[a-z]{1,10}){1}|(?([0-9\.]{2,5}){3,8}))(?\:[0-9]{1,6}){0,1}\/?(?(?[a-z0-9\-_%]{1,20}\/{1}){0,}(?[a-z0-9\-_]{1,20}\.{1}[a-z0-9]{2,6}){0,1}){0,1}(?(\/{1}[a-z_0-9\-_]{1,20}){1,}){0,10}(?\?{1}[a-z0-9%\+_\-&=\.@\!,\:]{0,200}){0,1}

2.使用MYSQL查询语句正则匹配身份证号(不带校验功能)

select field from table where column REGEXP '(1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5]|8[1-3])(0[1-9]|[1-6][0-9]|70|90)(0[1-9]|1[0-8]|2[1-9]|[3-9][0-9])(19|20)[0-9]{2}(0[1-9]|1[0-2])([0-2][1-9]|[1-2]0|31)([0-9]{4}|[0-9]{3}[Xx])';

3.Nginx日志分析正则

(?((?:[0-9]{1,3}\.){3}[0-9]{1,3})) (?\S+) (?\S+) \[(?[\w:\/]+\s[+|-]\d{4})\] \"(?\S+)\s?(?\S+)?\s?(?\S+)?\" (?\d{3}|-) (?\d+|-)\s?\"?(?[^\"]*)\"?\s\"?(?[^\"]*)\"

4.URL提取正则(支持多种协议及文本URL提取)

(?:(href|src)=["|']?)?((?:(http[s]?|ftp)?:\/\/.)?(?:(mailto|tel)?:)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:;%_\+.~#?&\/\/=]*))(?:["|']?)?

标签: 正则表达式

添加新评论