Remove HTML child inside its parent
Question: I have some HTML like this:

    
    
    <ul>
      <li>Item 1</li><br>
      <li>Item 2</li><br>
      <li>Item 3</li><br>
    </ul>
    
    <img src="someImage.png"><br>
    

And I would like to remove the `<br>` tags from after the `<li>` tags and the
`<img>` tags using regex though I'm not sure how to go about this. The HTML
does not remain the same, so the image and lists may be in a different
location or there may be other content though there will always be a `<br>`
after a `</li>` and `</img>`

What regex could I use to solve this with python? Thanks.

**Edit:**

I tried using this `(<img.+?>)<br>` for the image but it did not work.

I don't want to just simply remove ALL of the `<br>` tags because there may be
some useful ones in the HTML, rather I would like to have the ones after the
list items and images removed.


Answer: This is one way to remove the `br` tags:

    
    
    import re
    print re.sub('<br>', "", '<li>Item 1</li><br>')
    

If there are many `br` tags in your document you have to store the data in a
variable like this:

    
    
    data = 'your full html document as a string'
    print re.sub('<br>', "", data)
    

Then this will remove all the `br` tags in the entire `data` document.

If you only want to remove the `br` tags that are after the `li` tags then you
can do it like this:

    
    
    data = 'your full html document as a string'
    print re.sub(r'^<li>\<br>', "", data)
    

