How to remove tags from a string in python using regular expressions? (NOT in HTML)

前端 未结 6 1148
终归单人心
终归单人心 2020-12-07 23:22

I need to remove tags from a string in python.

Title

What is the most effici

6条回答
  •  情书的邮戳
    2020-12-08 00:06

    Please avoid using regex. Eventhough regex will work on your simple string, but you'd get problem in the future if you get a complex one.

    You can use BeautifulSoup get_text() feature.

    from bs4 import BeautifulSoup
    
    text = 'Title'
    soup = BeautifulSoup(text)
    
    print(soup.get_text())
    

提交回复
热议问题