Hello!

Using the following text:

http://www.google.com <a href="http://www.google.com">fail a match here</a>
I want to produce this:
<a href="http://www.google.com">http://www.google.com</a> <a href="http://www.google.com">fail a match here</a>
But, I am struggling a bit. This is what I have so far:
my $text = qq~ http://www.google.com <a href="http://www.google.com">fail a match here</a> ~; $text =~ s#(http://[^\s]*)(?!["|<])#<a href="$1">$1</a>#gsi; print $text;
But, it is not quite doing what I want, it is still matching the second line even with the lookahead of (?!"|<) I am guessing I can't use | to mean "or" here.

I want my regex to "find any instance of a url not followed by a quote or a carrot" which will replace all urls with clickable links (except those that already have anchor tags around them). Different approaches to this (instead of the lookahead) are fine with me.

Thanks!

Update

This does what I need:

s#[^">](http://[\S]*)# <a href="$1">$1</a>#gsi;
I gave up on the lookahead and just used a character class before the match. I hate giving up on something like that, but oh well :) thanks for all your input (Tokenize will come in handy ikegami, thanks!)

In reply to Regex: Lookahead by Rodster001

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.