|
|
| Perl Monk, Perl Meditation | |
| PerlMonks |
Re: regex to identify http:// in htmlby polypompholyx (Hermit) |
| on Nov 26, 2005 at 14:03 UTC ( #511884=note: print w/ replies, xml ) | Need Help?? |
|
For a quick hack, s{(http://\S+?)(\s+)}{<a href="$1">$1</a>$2} will do what you ask. The important thing to note is the \S+?, which makes the regex non-greedy, i.e. it'll match the minimum amount required for the regex to succeed, rather than the maximum amount, which is what \S+ or .* would do. I've also used \S (any non-space character), as it's best to avoid . where you can: see death to dot star.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||