62,614
社区成员
发帖
与我相关
我的任务
分享
1.<img href='www.baidu.com' id='new'>
2.<img href='www.google.com' id='new'/>
3.<img href='www.baidu.com' id='new'>图片</img>
String str = "(?i)<img\\b[^>/]*(?:/>|>(?:[^<]*</img>)?)";
public class RegexTest {
public static void main(String[] args) {
String str = "你不 <img href='www.baidu.com' id='new'>是吧abc <img href='www.google.com' id='new'/>图片 <img href='www.csdn.com' id='new'>点击跳转 </img>";
Pattern p = Pattern.compile("<img[^>]*>(.[^<]*</img>)?");
Matcher m = p.matcher(str);
while (m.find())
System.out.println(m.group());
}
}
public class RegexTest {
public static void main(String[] args) {
String[] strs = { "<img href='www.baidu.com' id='new'>sdfsdf<a></a>",
"<img href='www.google.com' id='new'/>asdasdasd<tr></tr>",
"<img href='www.baidu.com' id='new'>图片</img><body></body>" };
Pattern p = Pattern.compile("<img[^>]*>(.*</img>)?");
Matcher m = null;
for (String str : strs) {
m = p.matcher(str);
while (m.find())
System.out.println(m.group());
}
}
}