【发布时间】:2021-07-06 19:42:33
【问题描述】:
我有一些字符串包含一些 HTML 标签,如 <strong>、<em> 和 <br/>,我需要分别用 *、_ 和 \n 替换这些标签;
例如:
"this string contain <strong>bold</strong> and <em>italic</em> formatted text.<br/>How can I substitute these <strong><em>HTML tags</em></strong> with <strong>Python</strong>?"
必须成为
"this string contain *bold* and _italic_ formatted text.\nHow can I substitute these *_HTML tags_* with *Python*?".
执行此操作的最佳做法是什么?也许正则表达式?怎么样?
【问题讨论】:
标签: python html regex string replace