Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex problem

Status
Not open for further replies.

redgenie

Programmer
Aug 10, 2000
36
GB
Hello,

This should be a pretty easy one for most peeps, 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 " or "
Here is what I have so far.

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


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.
 
Code:
#!/usr/bin/perl

$string = 'blah blah blah [URL unfurl="true"]http://www.tek-tips.com[/URL] blah blah blah [URL unfurl="true"]http://tek-tips.com[/URL] blah blah blah [URL unfurl="true"]www.tek-tips.com';[/URL]

while ($string =~ m|(([URL unfurl="true"]http://)?(www\.)?([/URL][^\s<"']+)\.com)|g) {
  print "$1\n";
}


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top