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

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

Comments

Snippets Manager replied on Thu, 2006/03/23 - 2: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?