Python- Regular expression to match" <textarea> </textarea> " and anything between them
Question: If the text was

`<textarea>` **xyz asdf qwr** `</textarea>`

I'm trying to write a regular expression which will help me extract the text
in **bold**.

So far I have reached `[(<textarea)][</textarea>)]` which will capture the
tags but I haven't been able to actually capture the text in between the two
tags.

I also tried `[(<textarea)]+.[</textarea>)]` and even
`[[(<textarea)]+.[</textarea>)]` but that too isn't giving the right results.

Can someone please throw some light on this or share some links which will
help me reach a solution?


Answer: Is there a particular reason that you must use regular expression to parse
what seems like HTML? I wouldn't do it. See [RegEx match open tags except
XHTML self-contained tags](http://stackoverflow.com/questions/1732348/regex-
match-open-tags-except-xhtml-self-contained-tags) for the best explanation.

This becomes really simple if you use the
[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) module, which
is going to be far better at parsing HTML (especially if it is messy HTML).

    
    
    import bs4
    
    f = open("test.html")
    soup = bs4.BeautifulSoup(f)
    
    for textarea in soup.find_all('textarea'):
        print textarea.get_text()
    

