in reply to Regex check Valid URL

I have already picked one that best suits my needs

If you already chosen the best one, what do you want to discuss more?

what is the URL you are trying to validate?

what is the best Regex you chosen?


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^2: Regex check Valid URL
by hankcoder (Scribe) on Aug 17, 2015 at 10:26 UTC

    vinoth.ree, the said regex may not serve you any good but it may serve someone else. Furthermore, as to my knowledge, there are too many variant of url to validate for just one single prefect regex. And I am not looking for perfect regex.

    The previous regex I tested which I found on public internet are not able to serve my requirement.

    ^(http(?:s)?\:\/\/[a-zA-Z0-9]+(?:(?:\.|\-)[a-zA-Z0-9]+)+(?:\:\d+)?(?:\ +/[\w\-]+)*(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w] ++\=[\w\-]+)*)$
    Test URL:<br> http://www.abc.com/test.pl?a=1234 http://www.abc.com/?a=1234

    The above regex failed on 2nd url which it should be valid as well. My current successful tested regex that works for my need are:

    # @stephenhay (38 chars) ^(https?|ftp)://[^\s/$.?#].[^\s]*$ # @imme_emosol (54 chars) (https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?$

    There isn't a need to discuss further if you feel there isn't a need to.

    Perhaps this post should be in Meditations instead.