remove Img Tag using regex - Android java.util.regex

Android examples for java.util.regex:HTML Pattern

Description

remove Img Tag using regex

Demo Code


//package com.java2s;

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

public class Main {

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

    public static String removeImgTag(String html) {
        Matcher m = patternImg.matcher(html);
        while (m.find()) {
            html = m.replaceAll("");
        }/* w  ww.  j  a  va  2 s  .  com*/
        return html;
    }
}

Related Tutorials