0

I am having problems with my regex. It's returning the first match when I want it to return the last match.

Regex Pattern:

(?si)&chg_id= *?(.*?)\"

String being searched:

Display charges for the period 2010-05-04 11:21:00 to 2010-06-10 23:59:59

<A HREF="index.php?function=view_all_mobile&plan_id=224158&chg_id=1861161"><P>Display the period 2010-06-11 00:00:00 to 2010-07-10 23:59:59</A>
<A HREF="index.php?function=view_all_mobile&plan_id=224158&chg_id=2033934"><P>Display the period 2010-07-11 00:00:00 to 2010-08-10 23:59:59</A>
<A HREF="index.php?function=view_all_mobile&plan_id=224158&chg_id=2217641"><P>Display the period 2010-08-11 00:00:00 to 2010-09-10 23:59:59</A>
<A HREF="index.php?function=view_all_mobile&plan_id=224158&chg_id=2411848"><P>Display the period 2010-09-11 00:00:00 to 2010-10-10 23:59:59</A>
<A HREF="index.php?function=view_all_mobile&plan_id=224158&chg_id=2615705"><P>Display the period 2010-10-11 00:00:00 to 2010-11-10 23:59:59</A>
<A HREF="index.php?function=view_all_mobile&plan_id=224158&chg_id=2830781"><P>Display the period 2010-11-11 00:00:00 to 2010-12-10 23:59:59</A>

My expression is returning 1861161 but I want it to return 2830781 instead.

bebeTech
  • 153
  • 2
  • 13
  • 3
    Obligatory: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –  Nov 20 '10 at 13:37
  • Sorry, that didn't work. I am using http://gskinner.com/RegExr/ to test the regex. – bebeTech Nov 21 '10 at 10:50

1 Answers1

0

Why not use a DOM parser and grab all anchors on the page ( getElementsByTagName('a') ), get their href ( getAttribute('href') ), filter based on the href value, then grab the last one that matches the pattern?

meder omuraliev
  • 183,342
  • 71
  • 393
  • 434