DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Strip Html Tags

  • submit to reddit
import re
text = re.replace('<.*?>', '', html)


Snippets Manager replied on Thu, 2006/03/23 - 1:37am

There are all kinds of terrible things which can go wrong with that method. There's no reason to trust that ">" characters don't appear inside ALT attributes of images, for instance. Does this also assume that the tags are all on the same line?