62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test{
public static void main(String[] args){
String content = "<img src=\"invalid\" attr1=\"value1\"/>this is the img tag <img src=\"33show11\" attr1=\"value1\"/> test content <img attr2=\"value2\" src=\"fdshowa\" attr3=\"value3\">not content</img>";
String regex = "<img(\\s+(?!src=)\\w+\\s*=\"[^\"]+\")*(\\s+src\\s*=\"[^\"]*show[^\"]*\")(\\s+(?!src=)\\w+\\s*=\"[^\"]+\")*\\s*(/>|>.*</img>)";
Matcher matcher = Pattern.compile(regex).matcher(content);
while(matcher.find()){
System.out.println(matcher.group(0));
}
}
}