I need a regular expression that would let me validate Url. I found this one:
"^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$"
But my problem is that besides regular urls, I need to allow .cgi paths, without “http(s)”, like this:
123.45.678.543:30/cgi-bin/blah/blah.cgi
Could you please help me figure out how I could add this to the expression above?
Thanks.
It does not seem to me that the RegExp you posted is general enough to validate any types of URLs. Have a look at What is the best regular expression to check if a string is a valid URL? (especially @eyelidlessness’s answer) to maybe find more elaborate one.
The problem with your URL is not that it points to some cgi file. The problem is that it should – at least (in the case you are probably (?) talking about) – be
Besides that the numbers in an IP address can be 255 at maximum.
Even with these corrections it would still not qualify applying the RegExp you posted, but this is only one more hint to the faultiness of your RegExp.