使用正则表达式修改 HTML 字符串



>例如,我需要帮助从HTML字符串的标签中删除属性

<div remove="value" class="test"></div>

我正在尝试使用正则表达式删除标签

(htmlStr.replace(new Regexp('remove="value"','g'),""). 

我想要的最终输出是<div class="test"></div>

给定这样的 HTML:

<div remove="value" class="test" data-color="red"></div>

您可以替换某些属性(例如 removedata-color)与这样的正则表达式。

htmlStr.replace(/ [remove|data-color]*?=".*?"/g, "")

输出:

<div class="test"></div>

最新更新