Python: Remove text between <Table></Table> from text
Question: I am still relatively new to the use of `regex` in Python and I am struggling
to find a way to remove the content between the tags in a very simple .txt
file. See this
[file](https://www.dropbox.com/s/tnpm55xe1ovh7ow/0001047469-98-044981.txt?dl=0)
for example.

Here's what I've tried:

    
    
    fdir = open("C:\\file.txt")
    line = fdir.read()
    line = line.lower()
    pattern = re.compile("(?is)<table[^>]*>(.*?)<\/table>", re.MULTILINE)
    line = pattern.sub('', line)
    

and

    
    
    fdir = open("C:\\file.txt")
    line = fdir.read()
    line = re.sub(r"(?is)<table[^>]*>(.*?)<\/table>", '', line, re.DOTALL)
    

Both codes simply remove the tags `<Table>` and `<\Table>` in my text file and
not what is in between. What's missing in my code? **I want the tags to be
deleted as well.**


Answer: You should consider using
[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/bs4/doc/) to
remove these tags ...

    
    
    >>> from bs4 import BeautifulSoup
    >>> soup = BeautifulSoup(html)
    >>> for t in soup.find_all('table'):
    ...     t.decompose()
    

