in reply to Re: Re: Regex isn't performing like I think it should
in thread Regex isn't performing like I think it should
and when I run it, I get this:#!/usr/bin/perl -w my $string = '<a href="page.cfm?objectid=11933900&method=full&siteid=5 +0144"> Costly false alarms </a> <a href="page.cfm?objectid=11933890&m +ethod=full&siteid=50144"> Mindless yobs terrorise OAPs </a> <a href=" +page.cfm?objectid=11933879&method=full&siteid=50144"> Road deaths </a +> <a href="page.cfm?objectid=11933842&method=full&siteid=50144"> Twis +ted porn pervert caged for life </a> <a href="page.cfm?objectid=11933 +800&method=full&siteid=50144"> Greenbelt homes plan appeal thrown out + </a>'; while ( $string =~ m!(<a[^>]*>)(.+?</a[^>]*>)!ig ) { print "1st match: $1 \n"; print "2nd match: $2 \n\n"; }
which I think is what you want. I first tried just doing a single "$string =~ m!(<a^>*>)(.+?</a^>*>)!ig" and then printing out $1, $2,...$8, and only got values for the first two. That "while" thing seems a little shady, for the reason I put in my updated post above, but it seems to work in this case.1st match: <a href="page.cfm?objectid=11933900&method=full&siteid=5014 +4"> 2nd match: Costly false alarms </a> 1st match: <a href="page.cfm?objectid=11933890&method=full&siteid=5014 +4"> 2nd match: Mindless yobs terrorise OAPs </a> 1st match: <a href="page.cfm?objectid=11933879&method=full&siteid=5014 +4"> 2nd match: Road deaths </a> 1st match: <a href="page.cfm?objectid=11933842&method=full&siteid=5014 +4"> 2nd match: Twisted porn pervert caged for life </a> 1st match: <a href="page.cfm?objectid=11933800&method=full&siteid=5014 +4"> 2nd match: Greenbelt homes plan appeal thrown out </a>
|
|---|