Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Extract urls from string

perl, url, extract



10:22 am on May 30, 2004 (gmt 0)

10+ Year Member


I'm hoping someone can help me here. I'm trying to extract a list of urls from a string.

Remembering that urls could be typed "http://blahblah.com" or "www.blahblah.com".

Here is what I have so far.

my @links = $textString =~ m#((www\.¦http://)[^\s<"']+)#gm;

It seems to be working fine in most scenarios except that I always get an extra www. or http:// because of the parenthesis around the "or" condition.

Any help would be greatly appreciated.


8:48 pm on May 30, 2004 (gmt 0)

10+ Year Member

I suppose you could make the http optional, and also use \b to make it easier to find word boundaries:




4:34 am on May 31, 2004 (gmt 0)

10+ Year Member

Writing a regular expression to find URLs is like finding the Holy Grail: Ain't gonna happen, because it doesn't exist.

It's time to learn about Perl modules: URI-Find-0.13 [search.cpan.org]


10:56 am on May 31, 2004 (gmt 0)

10+ Year Member

Thanks very much for your help :)

Featured Threads

Hot Threads This Week

Hot Threads This Month