CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
URL's

 



parham_m_s
journeyman

Apr 25, 2001, 1:46 PM

Post #1 of 2 (1774 views)
URL's Can't Post

is there a snippet of code that replaces _any_ string url with actual link urls?



localfilmmaker
stranger

May 8, 2001, 11:11 AM

Post #2 of 2 (1752 views)
Re: URL's [In reply to] Can't Post

You can try this:

Code
my $text = 'this is text with a link to http://www.perl.com and to www.perldoc.com'; 

$text =~ s!(^|\s)(http://\S+)!<a href="$2">$2</a>!ig; # get all 'http://' links
$text =~ s!(^|\s)(www\.\w+\.\S+)!<a href="http://$2">$2</a>!ig; # get anything that simply starts 'www.'

print $text;

This seems to work, but you may try tweeking it to make it more robust.


-localfilmmaker
Spencer Christensen
spencer@mecworks.com

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives