Welcome to WebmasterWorld Guest from 23.22.220.37

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)

New User

10+ Year Member

joined:Mar 21, 2004
posts:24
votes: 0


Hello,

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)

Preferred Member

10+ Year Member

joined:Dec 30, 2003
posts:428
votes: 0


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

m/\b((http://)?www.*?)\b/mg

Sean

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

Preferred Member

10+ Year Member

joined:Jan 25, 2002
posts:378
votes: 0


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)

New User

10+ Year Member

joined:Mar 21, 2004
posts:24
votes: 0


Thanks very much for your help :)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members