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/.-]*$
精彩评论