【发布时间】:2021-10-16 13:29:09
【问题描述】:
(编辑)这应该在 nodeJS 后端应用程序中实现,因此尽量避免 DOMParser()
我有一个混合文本和标签的字符串,如下所示:
This is a comment
<img width="232" alt="CleanShot 2021-08-13 at 10 03 02@2x" src="https://user-images.githubusercontent.com/10532381/129324867-83b2e2bf-52c7-4dc6-a8b6-760194e2a875.png">
Some more comment
<img width="232" alt="CleanShot 2021-08-13 at 10 03 02@2x" src="https://user-images.githubusercontent.com/10532381/129335514-e7e921e9-eb1e-4848-b197-a2438bcc7bd3.png">
This is the end of the comment
我想创建一个函数,用 src 标签内的内容替换 标签,如下所示:
This is a comment
https://user-images.githubusercontent.com/10532381/129324867-83b2e2bf-52c7-4dc6-a8b6-760194e2a875.png
Some more comment
https://user-images.githubusercontent.com/10532381/129335514-e7e921e9-eb1e-4848-b197-a2438bcc7bd3.png
This is the end of the comment
我玩过 Regex,但找不到让它工作的方法。欢迎任何建议!
【问题讨论】:
-
你想用 src URL 做什么?
-
我将其发送到 Slack 对话,以便 Slack 显示缩略图
标签: javascript html node.js regex