Question: I am trying to strip all divs.

Input:

```
<p>111</p>

<div class="1334">bla</div>

<p>333</p>

<p>333</p>

<div some unkown stuff>bla2</div>

```

Desired Output:

```
   <p>111</p>

    <p>333</p>

    <p>333</p>

```

I tried this but it isn't working:

```
release_content = re.sub("/<div>.*<\/div>/s", "", release_content)

```

Answer: 
[Do not use regex for this problem](https://stackoverflow.com/a/1732454/1253312). Use an html parser. Here is a solution in python with BeautifulSoup:

```
from BeautifulSoup import BeautifulSoup

with open('Path/to/file', 'r') as content_file:
    content = content_file.read()

soup = BeautifulSoup(content)
[div.extract() for div in soup.findAll('div')]

with open('Path/to/file.modified', 'w') as output_file:
    output_file.write(str(soup))

```
You are using a *greedy* operator: `*`. It will try to match as much as possible before it stops. You can try using the non-greedy version, `*?`. So long as you don't have nested `<div>` tags you will be OK.

```
release_content = re.sub("(?s)<div>.*?<\/div>", "", release_content)

```

If you can have nested `<div>` tags, then you'll want to use an HTML library like [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/).

Per your edit, to account for attributes you can simply amend the leading `<div>` of the pattern:

```
release_content = re.sub("(?s)<div(?: [^>]*)?>.*?<\/div>", "", release_content)

```