我正在寻找一个正在寻找HTML标签中的属性的正则表达式模式.具体来说,我想找到......的所有实例
style=""
Run Code Online (Sandbox Code Playgroud)
...并将其从包含在其中的HTML标记中删除.显然,这将包括双引号中包含的任何内容.
我正在使用经典ASP来做到这一点.我已经为不同的正则表达式模式设置了函数,该模式查找字符串中的所有HTML标记并将其删除.它很棒.但现在我只需要另一种模式来专门删除所有样式属性.
任何帮助将不胜感激.
Jas*_*aro 20
我想这可能会这样做:
/style="[a-zA-Z0-9:;\.\s\(\)\-\,]*"/gi
如果您只想更换某些部件,也可以将它们放入捕获组中
/(style=")([a-zA-Z0-9:;\.\s\(\)\-\,]*)(")/gi
工作示例: http ://regexr.com?2up30
小智 5
试试这个,它将完全取代 style 属性及其值
const regex = /style="(.*?)"/gm;
const str = `<div class="frame" style="font-family: Monaco, Consolas, "Courier New", monospace; font-size: 12px; background-color: rgb(245, 245, 245);">some text</div>`;
const subst = ``;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);Run Code Online (Sandbox Code Playgroud)