Match url beginning with http:// or nothing.

Discussion in 'Perl Misc' started by Heckner, Jul 11, 2005.

  1. Heckner

    Heckner Guest

    Hi

    I tried /(http:\/\/w+|^§)/ as the regex for matching an url beginning
    with http:// or an empty string.
    Problem is the empty string is not matched. Any idea?
    Best regards
    Hannes
    Heckner, Jul 11, 2005
    #1
    1. Advertising

  2. Heckner

    Guest

    well im not sure what it is but that "empty string" character is either
    wrong or just displaying wrong here, this is what you would want

    /(http:\/\/\w+|\s+)/ you missed the \ for the w+ and the s+ hopefully
    this will fix your problem :)
    , Jul 11, 2005
    #2
    1. Advertising

  3. Heckner wrote:
    > I tried /(http:\/\/w+|^§)/ as the regex for matching an url beginning
    > with http:// or an empty string.
    > Problem is the empty string is not matched. Any idea?


    It matches a section sign as expected. You mean

    /(http:\/\/w+|^$)/
    -------------------^

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jul 11, 2005
    #3
  4. Gunnar Hjalmarsson <> writes:

    > Heckner wrote:
    >> I tried /(http:\/\/w+|^§)/ as the regex for matching an url beginning
    >> with http:// or an empty string.
    >> Problem is the empty string is not matched. Any idea?

    >
    > It matches a section sign as expected. You mean
    >
    > /(http:\/\/w+|^$)/
    > -------------------^


    In addition, you could avoid "leaning toothpick syndrome" by using a different
    delimiter for the match:

    m%(http://w+|^$)%

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
    Sherm Pendley, Jul 11, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ravi
    Replies:
    20
    Views:
    735
    Andrew Dalke
    Aug 22, 2003
  2. Lars Schouw
    Replies:
    1
    Views:
    362
    Sousuke
    Mar 26, 2010
  3. Jesse B.
    Replies:
    9
    Views:
    221
    Jesse B.
    Mar 27, 2010
  4. Devin Jeanpierre
    Replies:
    2
    Views:
    431
    Devin Jeanpierre
    Feb 14, 2012
  5. John

    regex match on nothing

    John, Mar 4, 2010, in forum: Perl Misc
    Replies:
    3
    Views:
    124
Loading...

Share This Page