【发布时间】:2021-09-01 23:18:22
【问题描述】:
我只是想用这样的 HTML 部分替换以下文本
designed to display special types of text:<b>- Bold text<strong> - Important text<i> - Italic text<em> - Emphasized text<mark> -
使用此正则表达式将 &lt; 和 &gt; 之间的所有内容替换为空
html = html.replace("/(<\/*\w+?>)/g", '');
但我的正则表达式似乎不起作用,如何获得准确的?
【问题讨论】:
-
您缺少
/开头 - 这将显示在您的浏览器控制台中。但听起来像是一个 XY 问题——你从哪里得到原始字符串? -
我从这个页面得到w3schools.com/html/html_formatting.asp,我刚刚更新了正则表达式'(<\/*\w+?>)'
-
好的 - 所以它只是在您的代码中定义的一个字符串 (
var html = '...') - 如果您使用 jquery 从页面获取它,例如$("#id").html(),那么简单的解决方案是使用 @ 987654329@ 而不是.html()
标签: javascript jquery regex nsregularexpression