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'><img src='http://groups.google.com/ intl/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 For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en