Earlier this week I needed to remove some HTML tags from a text, the target string was already recorded with HTML tags in the database and one of the requirement specifies that in some specific page we need to render it as a raw text.
I knew from the beginning that regular expressions could apply for that challenge, but since I am not an expert with regular expressions I looked for some advise in stack overflow and then I found what I actually needed.
Below is the function I have defined:
"""Remove html tags from a string"""
clean = re.compile('<.*?>')
return re.sub(clean, '', text)
Latest posts by admin (see all)
- Install and Running Supervisord in virtualenv python 2.7 - January 24, 2019
- Urgent fix: Briefly unavailable for scheduled maintenance. Check back in a minute. - January 22, 2019
- Change WordPress post date format to time ago - January 21, 2019
Also published on Medium.