That's almost perfect, thanks!!! But how can I avoid src='' or src=""? I
want the values only, i.e. the image paths themselves.

On Fri, Dec 18, 2009 at 3:07 PM, Dillard, Derek <ddill...@deluxe.com> wrote:

> Hello Vunet,
> Change your code to this (note my comments):
>
> String imageString = "<img src='http://groups.google.com/intl/en/
> images/logos/groups_logo_sm.gif<http://groups.google.com/intl/en/%0Aimages/logos/groups_logo_sm.gif>'><img
> src='http://groups.google.com/
> intl/en/images/logos/groups_logo_big.gif<http://groups.google.com/%0Aintl/en/images/logos/groups_logo_big.gif>
> '>";
> Pattern src =
> Pattern.compile("src=(?:\"|\')?(?:[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
> Matcher matcher = src.matcher(imageString);
> int i = 0;//no need for this
> while (matcher.find()) {//This will find all matches on its own.
> System.out.println("source is "+matcher.group());
> i++;//or this
> }
>
> I think that will give you what you're looking for. HTH.
>
> -D.
>
>
> -----Original Message-----
> From: java-ee-j2ee-programming-with-passion@googlegroups.com [mailto:
> java-ee-j2ee-programming-with-pass...@googlegroups.com] On Behalf Of vunet
> Sent: Friday, December 18, 2009 9:40 AM
> To: Java EE (J2EE) Programming with Passion!
> Subject: [java ee programming] Regex to Match All Source Attributes in HTML
> IMG Tag
>
> Hello,
> I am trying to get all src attribute values in HTML IMG tags with
> Regex. SInce I am not an expert in Regex I found one online which
> seems to work well for many users:
>
> src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?
>
> However, when I plug it in my Java code it throws an error below. Any
> advice? Thank you very much.
>
> Code:
> String imageString = "<img src='http://groups.google.com/intl/en/
> images/logos/groups_logo_sm.gif<http://groups.google.com/intl/en/%0Aimages/logos/groups_logo_sm.gif>'><img
> src='http://groups.google.com/
> intl/en/images/logos/groups_logo_big.gif<http://groups.google.com/%0Aintl/en/images/logos/groups_logo_big.gif>
> '>"
> Pattern src = Pattern.compile("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].
> (?:jpg|bmp|gif|png))(?:\"|\')?");
> Matcher matcher = src.matcher(imageString);
> int i = 0;
> while (matcher.find(i)) {
> System.out.print("source is "+matcher.group());
> i++;
> }
>
> Error:
>
> Invalid data: java.util.regex.PatternSyntaxException: Look-behind
> group does not have an obvious maximum length near index 50
> src=(?:"|')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:"|')?
>                                                  ^|#]
>
> [#|2009-12-17T14:56:06.625-0500|WARNING|sun-appserver-pe8.2|
> javax.enterprise.system.stream.err|_ThreadID=13;|
> java.util.regex.PatternSyntaxException: Look-behind group does not
> have an obvious maximum length near index 50
> src=(?:"|')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:"|')?
>                                                  ^
>         at java.util.regex.Pattern.error(Pattern.java:1713)
>         at java.util.regex.Pattern.group0(Pattern.java:2488)
>         at java.util.regex.Pattern.sequence(Pattern.java:1806)
>         at java.util.regex.Pattern.expr(Pattern.java:1752)
>         at java.util.regex.Pattern.compile(Pattern.java:1460)
>         at java.util.regex.Pattern.<init>(Pattern.java:1133)
>         at java.util.regex.Pattern.compile(Pattern.java:823)
>         at org.apache.jsp.ecatalogue.fhtml.pdf_jsp._jspService
> (pdf_jsp.java:423)
>
> --
> You received this message because you are subscribed to the Google
> Groups "Java EE (J2EE) Programming with Passion!" group.
> To post to this group, send email to
> java-ee-j2ee-programming-with-passion@googlegroups.com
> To unsubscribe from this group, send email to
> java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com<java-ee-j2ee-programming-with-passion%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
>
> http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
>
>
>


-- 
Vadym Ustymenko
Systems Consultant &
Senior Web Developer
917.589.4237
vu...@vunet.us
http://www.vunet.us

-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

Reply via email to