我需要从html属性中删除"style“属性,我用这个正则表达式实现了这个目标:
"<div id='mioId' style='color:black;background-color:red' attr='stuff' class='myClass' />".replace(/style=('|")[^('|")]*\1/, '')我想做的是,使用反向引用也匹配内容。就像这样:
"<div id='mioId' style='color:black;background-color:red' attr='stuff' class='myClass' />".replace(/style=('|")[^\1]*\1/, '')在我看来,最后一个解决方案应该有效,但是正则表达式似乎不符合我的观点.
注:我对其他方法感兴趣,我只想了解我做错了什么
发布于 2014-08-21 22:13:10
反向引用不能在字符类中使用。
不必使用否定的字符类,而是必须使用负前瞻。
.replace(/style=(['"])(?:(?!\1).)*\1/, '')https://stackoverflow.com/questions/25436707
复制相似问题