开发者

help for Url detection regex

开发者 https://www.devze.com 2022-12-22 10:54 出处:网络
I hope this question is not a duplicate but I didn\'t find anything equivalent on SO. I want a regex for checking an URL.

I hope this question is not a duplicate but I didn't find anything equivalent on SO.

I want a regex for checking an URL.

The given URL can be local /some-text or extern开发者_JAVA技巧al http://theurl

I am trying ^http://|/[-\w/\.]+$ but it doesn't work.

I don't know how to write the optional http://. Any help?

Thanks


Try:

^(https?://|/)[\w/.-]+$

or, if you care about // at the begining:

^(https?://|/)[^/]+[\w/.-]*$
0

精彩评论

暂无评论...
验证码 换一张
取 消