Home | My New Hugo Project

Python3 - strip html tags from string

2022-03-23

Here is a code snippet to strip tags and leading and trailing whitespace

 

def remove_html_tags text):
        """Remove html tags from a string"""
        clean = re.compile('<.*?>')
        ntxt = re.sub(clean, '', text )
        return ntxt.strip()