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.


In reply to Re^2: Regex check Valid URL by hankcoder
in thread Regex check Valid URL by hankcoder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.