Did you try the using "while", as well? I've got 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"; }
and when I run it, I get this:
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>
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.

In reply to Re: Re: Re: Regex isn't performing like I think it should by jmarshall99
in thread Regex isn't performing like I think it should by Popcorn Dave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.