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!

Regular Expresson to Extrcat URLs from img src tags

807603Jan 23 2008 — edited Jan 24 2008
Hi,

I have a huge string containing html tags, some of these tags being <img src="URL"> ones. I need to extract the urls from all the occurences of these tags in the input string. This is what I am doing:


Pattern p=null;
Matcher m= null;
String word0= null;
String word1= null;
 
p= Pattern.compile(".*<img[^>]*src=\"([^\"]*)",Pattern.CASE_INSENSITIVE);
m= p.matcher(txt);
while (m.find())
     {
    word0=m.group(1);
    System.out.println(word0.toString());
     }
The problem with this code is that this prints only the last URL. For example if there are 5 <img src="URL"> tags, this code prints only the URL contained withn the 5th< img src> tag. Please tell me how to solve this.

Thanking you in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 21 2008
Added on Jan 23 2008
6 comments
401 views