Fellow monks,

I've got a problematic regex that I hope is something simple that I'm just overlooking.

Given a line of text (and yes that's one contiguous line):

a href="page.cfm?objectid=11933900&method=full&siteid=50144" Costly false alarms /a a href="page.cfm?objectid=11933890&method=full&siteid=50144" Mindless yobs terrorise OAP's /a a href="page.cfm?objectid=11933879&method=full&siteid=50144" Road deaths /a a href="page.cfm?objectid=11933842&method=full&siteid=50144" Twisted porn pervert caged for life /a a href="page.cfm?objectid=11933800&method=full&siteid=50144" Greenbelt homes plan appeal thrown out /a a href="page.cfm?objectid=11933742&method=full&siteid=50144" Youngsters invited to get in the swim /a a href="page.cfm?objectid=11933698&method=full&siteid=50144" Phone mast fears grow /a a href="page.cfm?objectid=11933695&method=full&siteid=50144" Vandals strike at cemetery /a a href="page.cfm?objectid=11928420&method=full&siteid=50144" Windfarm fears are no flights of fancy /a a href="page.cfm?objectid=11928280&method=full&siteid=50144" Mindless vandals wreck headstones /a a href="page.cfm?objectid=11928277&method=full&siteid=50144" Old Firm united to support hospice /a a href="page.cfm?objectid=11928275&method=full&siteid=50144" Family at war over the loss of buses /a a href="page.cfm?objectid=11928273&method=full&siteid=50144" Joining with Jubilations /a a href="page.cfm?objectid=11927986&method=full&siteid=50144" Catch the football fever at coaching days /a a href="page.cfm?objectid=11927859&method=full&siteid=50144" Radio Law ready to hit the airwaves /a
<'s and >'s have been removed to show the text non-html

and a regex of:

m!(<a[^>]*>)(.+</a[^>]*>)!ig

Shouldn't I get $1, $2, $3, etc... until I stop getting matches? All I'm getting at this point is $1 and $2, with $1 having the correct value and $2 having the rest of the string.

Shouldn't the </a[^>]*> match the first occurence of or am I misunderstanding something in my regex?

And yes I *know* I could be using a module to parse this, but this is the exact reason I'm doing it this way -- to better my understanding of regexes.

It also occured to me to split this in to an array and match it that way, but I was unsure on what I could split that on given the number of spaces between tags. Any advice on that would be great too!

Thanks in advance!

Some people fall from grace. I prefer a running start...


In reply to 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.