通过正则表达式匹配网址 [英] Matching a web address through regex
本文介绍了通过正则表达式匹配网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过正则表达式匹配一个应该捕获 http://www.google.com 的网址以及 www.google.com,即有和没有协议.
I want to match a web address through regex which should capture http://www.google.com as well as www.google.com i.e. with and without protocol.
推荐答案
嗯,这将取决于您想要捕获的确切内容(FTP"?/index.htm"?),因为一般的 URI 捕获基于RFC 标准非常难,但你可以从:
Well it's going to depend on exactly what you want to capture ("FTP"? "/index.htm"?) because a general URI capture based on the RFC standard is very hard, but you could start with:
/^((https?\:\/\/)?([\w\d\-]+\.){2,}([\w\d]{2,})((\/[\w\d\-\.]+)*(\/[\w\d\-]+\.[\w\d]{3,4}(\?.*)?)?)?)$/
复杂吗?
这篇关于通过正则表达式匹配网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文