万能的正则

1.分析URL正则

(?<protocol>[a-z]{2,6}):\/\/((?<subdomain>[a-z0-9]{0,10}\.{1}){0,2}(?<domain>[a-z\-0-9]{1,30}){1}\.{1}(?<extension>[a-z]{1,10}){1}|(?<ipaddress>([0-9\.]{2,5}){3,8}))(?<port>\:[0-9]{1,6}){0,1}\/?(?<filepath>(?<path>[a-z0-9\-_%]{1,20}\/{1}){0,}(?<filename>[a-z0-9\-_]{1,20}\.{1}[a-z0-9]{2,6}){0,1}){0,1}(?<route>(\/{1}[a-z_0-9\-_]{1,20}){1,}){0,10}(?<query>\?{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日志分析正则

(?<remote_addr>((?:[0-9]{1,3}\.){3}[0-9]{1,3})) (?<dash>\S+) (?<remote_user>\S+) \[(?<time_local>[\w:\/]+\s[+|-]\d{4})\] \"(?<request>\S+)\s?(?<path>\S+)?\s?(?<protocol>\S+)?\" (?<status_code>\d{3}|-) (?<body_bytes_sent>\d+|-)\s?\"?(?<http_referer>[^\"]*)\"?\s\"?(?<http_user_agent>[^\"]*)\"

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@:;%_\+.~#?&\/\/=]*))(?:["|']?)?