Using the following text:
I want to produce this:http://www.google.com <a href="http://www.google.com">fail a match here</a>
But, I am struggling a bit. This is what I have so far:<a href="http://www.google.com">http://www.google.com</a> <a href="http://www.google.com">fail a match here</a>
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.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;
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:
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!)s#[^">](http://[\S]*)# <a href="$1">$1</a>#gsi;
In reply to Regex: Lookahead by Rodster001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |