我想解决一些正常的表达式,我在一个方向工作,但失败时,我改变了属性。正则表达式属性替换
我想实现的就是找到对齐的价值并更换该数值到类
var s = '<img src="" align="left" class="smart" title="title for reference" />';
var reg = new RegExp(/(?:align="(.*?)").*?(?:class="(.*)")/);
console.log(s.replace(reg ,'class="image-$1 $2"'));
能正常工作和输出
<img src="" class="image-left smart" title="title for reference" />
,但如果我改变HTML放置类之前对齐我刚刚得到原始html字符串
强制性链接:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – 2011-03-16 19:27:54