开发者

Regex to return last found pattern?

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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜