프로그래밍/python
파이썬 문자열 안의 모든 html 태그 기본 태그로 치환
콘솔워크
2022. 12. 11. 14:47
반응형
import re
test_html = '<div class="test">hi</div>'
def findtags(text):
# make this non capturing group
return re.findall(r"<[^>]+>", text)
tags = findtags(test_html)
for tag in tags:
simple_tag = re.sub(r"(<\w+)[^>]+(>)", r"\1\2", tag)
test_html = test_html.replace(tag, simple_tag)
print(test_html)
반응형