python - 用 Python 替换一些带有特殊字符的 HTML 标签
问题描述
我有一些包含一些 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,但是</?strong>
用*
和</?em>
替换_
应该就可以了。
</?strong>
匹配<strong>
并且 </strong>
因为 ./
是可选的?
。
推荐阅读
- postgresql - 在 Windows 上复制的 Postgresql 权限被拒绝
- python-3.x - 如何使用 selenium 向下滚动 instagram 中的弹出关注者列表?(Python)
- email - 向 example.com 发送电子邮件是否会导致电子邮件发送服务被列入黑名单或其他问题?
- swift - 如何在 SwiftUI 中将文本推送到边缘
- r - 是否可以删除堆叠条边界线?
- python - detect.tflite v1 对同一对象失去信心( Python )
- discord.py - discord py - 在嵌入中实现贴纸
- reactjs - Ant Design:警告:[antd: Upload] `transformFile` 已弃用。请直接使用`beforeUpload` :ReactJs
- c# - 如何在 Visual Studio(社区)的 C# 中打开语法错误突出显示?
- excel - 如何从最近的电子邮件开始将电子邮件从 Outlook 拉到 Excel?