url1 = http://xyz.com/abc
url2 = http://xyz.com//abc
I want to write a regex
that validate both url1
and url2
url1 = http://xyz.com/abc
url2 = http://xyz.com//abc
I want to write a regex
that validate both url1
and url2
The answer depends on whether you want to parse urls in general or whether you just wonder how to handle the optional slash.
In the first case, I agree with Amber that you should use urlparse.
In the second case, use a ?
after the slash in your expression:
http://xyz.com//?abc
A ?
in a regular expression means that the previous element is optional (i.e. may appear zero times or once).