使用正则表达式验证 url [英] validate url with regular expressions
本文介绍了使用正则表达式验证 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试了所有可能的方法来获取 url 验证的正则表达式,但我没有得到任何..我需要的是网址可以像
I've gone through all possible ways for having the regular expression for the url validation, but I didn't get any.. what I need is the url can be like
google.com
http://google.com
https://google.com
http://www.google.com
https://www.google.com
但是如果它只是 google
最后,.extensions
是强制性的
我试过这个 /^[a-z0-9-]+(.[a-z0-9-]*)(.[a-z0-9-]*)$/代码>
任何人都可以在这种情况下帮助我..
can anyone help me in this case..
推荐答案
试试这个表达式
/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi
它会接受你上面提到的所有情况
It will aceept all the cases that you have mentioned above
这篇关于使用正则表达式验证 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文