Java String contain HTML <img> tag

Description

Java String contain HTML <img> tag


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String html = "<img src=''/>";
        System.out.println(IsContainImg(html));
    }//from   w w w .j a  va  2  s . c om

    static final Pattern patternImg = Pattern.compile("<img(.+?)src=\"(.+?)\"(.+?)(onload=\"(.+?)\")?([^\"]+?)>");

    public static boolean IsContainImg(String html) {
        Matcher m = patternImg.matcher(html);
        while (m.find()) {
            return true;
        }
        return false;
    }
}



PreviousNext

Related