Link to home
Start Free TrialLog in
Avatar of yeshengl
yeshenglFlag for United States of America

asked on

regular expression, pick up the last occurrance

Hi,

How do I pick up the last occurrance of a matching string by regular expression. For example: I have string:

<a href=url1><a href=url2>......<end>

I want to pick up the last url before "<end>"

I use regular expression pattern: "<a href=(.+?)><end>" and it gives me "url1><a href=url2>......".
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I find that parsing HTML is far easier than using regular expressions.

Here is a previous VB.NET question that highlights what I mean:

  https://www.experts-exchange.com/questions/21767542/extract-hyperlinks-from-HTML-in-VB-net.html

I have equivalent C# code.

Bob
Bob, could you post that C# code anyway ?
I'd like to have a play.
I can post a separate Q if you like...topic area of your choice :)
Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for that code, btw :)