PERL Search & Replace

Discussion in 'Perl Misc' started by Walt, Apr 21, 2006.

  1. Walt

    Walt Guest

    In the following single line @URLs will contains all urls from $omsg.

    @URLs = ($omsg =~/(\Shttp:\/\/| http:\/\/|\shttp:\/\/)(.*?)(<br>|\n|\r|
    )/gi);

    What I would like to have is a way to scan in the same line if there
    is an equal sign in front of http and if so, omit it.

    Is there a way to do it within the single line?
     
    Walt, Apr 21, 2006
    #1
    1. Advertising

  2. Walt

    David Squire Guest

    Walt wrote:
    > In the following single line @URLs will contains all urls from $omsg.
    >
    > @URLs = ($omsg =~/(\Shttp:\/\/| http:\/\/|\shttp:\/\/)(.*?)(<br>|\n|\r|
    > )/gi);
    >
    > What I would like to have is a way to scan in the same line if there
    > is an equal sign in front of http and if so, omit it.
    >
    > Is there a way to do it within the single line?
    >


    It is not clear if you mean directly in front, e.g. '...=http', or if it
    can be anywhere in front. The or'ing of '\S', ' ', and '\s' looks very
    odd: surely \S or'ed with \s matches everything, and ' ' is a subset of
    '\s'. Some sample data would make the question clearer.

    Still, this should do the trick:

    @URLs = ($omsg =~/[^=](http:\/\/)(.*?)(<br>|\n|\r|)/gi);

    (untested, as I can't know what your data is actually like).

    For future reference: perldoc perlre

    Regards,

    DS
     
    David Squire, Apr 21, 2006
    #2
    1. Advertising

  3. Walt

    ClubK Guest

    So, @URLs = ($omsg =~/[^=](http:\/\/)(.*?)(<br>|\n|\r|)/gi); should
    give me all urls that do not start with equal sign directly in front of
    http?

    Thanks for the reply. I titled the first post wrong deleted it and
    changed the tile. Sorry about that.

    I am very new at alot of this so some of my code practice is
    experimental.

    I am using this line to auto link urls in my forum so people don't
    have to. Convert the plain text http://www.clubknowledge.com to a
    clickable link but not a href=http://
     
    ClubK, Apr 21, 2006
    #3
  4. Walt

    David Squire Guest

    ClubK wrote:
    > So, @URLs = ($omsg =~/[^=](http:\/\/)(.*?)(<br>|\n|\r|)/gi); should
    > give me all urls that do not start with equal sign directly in front of
    > http?
    >


    Yep. Reading the manual will make that clear: perldoc perlre

    [snip]

    Please quote context and give attribution to its author when posting on
    Usenet. Read and follow the practices described at
    http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html to get the
    most out of this (and other) newsgroups.

    DS
     
    David Squire, Apr 21, 2006
    #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. Schif Schaf
    Replies:
    12
    Views:
    1,286
    Anthra Norell
    Feb 8, 2010
  2. Abby Lee
    Replies:
    5
    Views:
    421
    Abby Lee
    Aug 2, 2004
  3. walala
    Replies:
    21
    Views:
    215
    John W. Krahn
    Sep 23, 2003
  4. Ron M.
    Replies:
    4
    Views:
    130
    Tad McClellan
    Jan 5, 2004
  5. Michael
    Replies:
    2
    Views:
    80
    Gunnar Hjalmarsson
    Aug 24, 2004
Loading...

Share This Page