tags:

views:

44

answers:

1

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 external 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

A: 

Try:

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

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

^(https?://|/)[^/]+[\w/.-]*$
jasonbar
It doesn't work. / doesn't match
luc
@luc: Try what I have now. You probably want to just use `.+`, though.
jasonbar
I am using ^(https?://\w|/)[\w/.-]*$ Thanks for your help.
luc