Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Non greedy Java Regex not working

800368Feb 19 2010 — edited Feb 21 2010
I am trying to parse some HTML and using regex for it.

Here is the HTML I want to parse:
<a href="google.com">Lololo</a> <a href="tttt.com">Read More</a>
I want to find the second anchor tag with "Read More" text only.
The Regex I am using to parse the String is:
<a.*?>\s*Read More.*?</a>
But I am still getting the entire string back after the regex match instead of only the second A tag with Read More text.

Can anyone help explain what is wrong in my regex?

I am using Java 6 with Eclipse IDE 3.4.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 21 2010
Added on Feb 19 2010
23 comments
712 views