Have a string:
myString = '<p>Phone Number:</p><p>706-878-8888</p>'
Trying to regex out all HTML tags, in this case Paragraphs.
Thanks!
Have a string:
myString = '<p>Phone Number:</p><p>706-878-8888</p>'
Trying to regex out all HTML tags, in this case Paragraphs.
Thanks!
Use re.sub
:
>>> re.sub('<[^>]+>', '', '<p>Phone Number:</p><p>706-878-8888</p>')
'Phone Number:706-878-8888'
Using re
is a good solution if you just want to remove tags. But, if you're want to do things a little bit more complicated (involving HTML parsing) I suggest you to look into BeautifulSoup
.
Using BeautifulSoup as pointed out by a comment:
>>> from BeautifulSoup import BeautifulSoup
>>> BeautifulSoup(myString).text
u'Phone Number:706-878-8888'