java - How can I extract all substring by matching a regular expression? -


i want extract values of src attribute in string, how can that:

<p>test&nbsp; <img alt="70" width="70" height="50" src="/adminpanel/userfiles/image/1.jpg" /> test  <img alt="70" width="70" height="50" src="/adminpanel/userfiles/image/2.jpg" /> </p> 

here go:

string data = "<p>test&nbsp;\n" +     "<img alt=\"70\" width=\"70\" height=\"50\" src=\"/adminpanel/userfiles/image/1.jpg\" />\n" +     "test \n" +     "<img alt=\"70\" width=\"70\" height=\"50\" src=\"/adminpanel/userfiles/image/2.jpg\" />\n" +     "</p>"; pattern p0 = pattern.compile("src=\"([^\"]+)\""); matcher m = p0.matcher(data); while (m.find()) {   system.out.printf("found: %s%n", m.group(1)); } 

most regex flavors have shorthand grabbing matches, ruby's scan method or .net's matches(), in java have spell out.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -