开发者

help for Url detection regex

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜