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!

Pattern Matching

Status
Not open for further replies.

woompy

Programmer
Feb 22, 2002
9
AU
I need to use a regexp to match segments of a URL which contains javascript. The string is in this format, and I need to match the querystring and the name of the URL, which are in bold.
Code:
<!--videocode--><a href="javascript:MyPop('[URL unfurl="true"]http://yoursite.com?[/URL][b]src=[URL unfurl="true"]http://www.bolt.com/audio/audio_player_mp3_branded.swf?type=application/x-shockwave-flash&pluginspage=http://www.macromedia.com/go/getflashplayer[/URL][/b]','PlayVid',360,350,1,1)">[b]Name of URL[/b]</a><!--videocode-->
I've come up with this regexp which works.
Code:
$Txt =~ m!\<\!--videocode--\>.+?\?(.+?)\'.+?\>(.+?)\<\/a\>\<\!--videocode--\>!isg;
I'm not good when it comes to regexp, so is this ok or is there a better way to match this using regexp.

Thanks
Bob
 
Your regular expression is fine. I would only point out that the content of your regex is overly escaped. None of the <>'s need to be escaped, and the !'s would not need to be if you simply used a different delimiter for your regex. I've therefore changed the regex that you provided in such a way so as to reflect that below. I think that you'll find that it is much easier to read this way.

You'll also notice that I've removed the use of the modifers 'isg'.
[ul]
[li] 'i' because you don't really need case insensitive matching, or do you?[/li]
[li] 's' because you are not using or need the anchors ^$.[/li]
[li] 'g' because you do not want global matching, but instead only are matching a single time.[/li]
[/ul]

Code:
my $Txt = q{<!--videocode--><a href="javascript:MyPop('[URL unfurl="true"]http://yoursite.com?src=http://www.bolt.com/audio/audio_player_mp3_branded.swf?type=application/x-shockwave-flash&pluginspage=http://www.macromedia.com/go/getflashplayer','PlayVid',360,350,1,1)">Name[/URL] of URL</a><!--videocode-->};

# Old Regex - $Txt =~ m!\<\!--videocode--\>.+?\?(.+?)\'.+?\>(.+?)\<\/a\>\<\!--videocode--\>!isg;

$Txt =~ m{<!--videocode-->.+?\?(.+?)\'.+?>(.+?)</a><!--videocode-->};

print "1 = $1\n";
print "2 = $2\n";
 
a 4 letter domain requires 0 ad breaks ... :(

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks MillerH. I'm amazed I got that right. Maybe I'm learning something after all.
Thanks again
Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top