正则表达式匹配http链接

写正则表达式,匹配以下例如:
http://hello.hello.com和大海
http://hello.hello.com和大海
http://hello.aaa.com和大海
http://hello.hello.com.cn和大海
http://hello.hello.name和大海
http://hello.hello.top和大海
https://hello.hello.com和大海
http://hello.hello.com和大海
http://hello.hello.com和大海
http://hello.hello.hh
321和大海
http://hello.hello.cn?hello=aaa和大海
http://www.baicu.com?123=321
https://www.baicu.com?123=321 321

匹配非中文:[^\x{4e00}-\x{9fa5}]
匹配非空格回车换行:[^\n\r\s]

只匹配www.xxx.固定几个域名后缀 + 请求参数
严格模式(括号部分根据情况设置后缀):

https{0,1}://www\.[^\x{4e00}-\x{9fa5}\n\r\s]+\.((com)|(cn)|(info)|(com\.cn)|(top))[^\x{4e00}-\x{9fa5}\n\r\s]*

匹配http开头的就行
非严格模式:
https{0,1}://[^\x{4e00}-\x{9fa5}\n\r\s]{3,}

发布了46 篇原创文章 · 获赞 62 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/qq_27512671/article/details/84539348