Remove IMG tag from HTML using Regex - Python 2.7
<p>I have HTML and I want to remove IMG tag from it.</p>

<p>I am not good at regex, I have this function but it does not remove IMG tag</p>

<pre><code>def remove_img_tags(data):
    p = re.compile(r'&lt;img.*?/&gt;')
    return p.sub('', data)
</code></pre>

<p>What is the proper regex? I don't want to use any library.</p>

<p>All you need is to capture <code>img</code> tag and replace it with empty string.</p>

<pre><code>clean_data = re.sub("(&lt;img.*?&gt;)", "", data, 0, re.IGNORECASE | re.DOTALL | re.MULTILINE)
</code></pre>

<p>You'll be passing HTML content in <code>data</code>. Regex will remove all <code>img</code> tags, their content and return clean data in <code>clean_data</code> variable.</p>

python regex python-2.7