str='<p>dg<b style="color: rgb(255, 0, 0);">钢结构</b><b>v不错v吧</b>风格<b style="color: rgb(255, 0, 0);">梵蒂冈地方</b>的<span style="color: rgb(255, 0, 0);">二手单反</span></p>'
处理成
str='dg<font color="#FF0000"><b> 钢结构</b></font><b>v不错v吧</b>风格<font color="#FF0000"><b> 梵蒂冈地方</b></font>的<font color="#FF0000">二手单反</font>'
要求:
1.所有带style的b标签替换成<font color="#FF0000"><b>
2.所有style="color: rgb(255, 0, 0);"
换成color="#FF0000"
3.所有span标签换成font
let contentStyle=this.content.replace(/<\/?p[^>]*>/gi,'')
contentStyle=contentStyle.replace(/span/g, 'font')
console.log(contentStyle)
contentStyle=contentStyle.replace(/</g, '<')
contentStyle=contentStyle.replace(/>/g, '>')
var reg4 = /style="[^=]*?"([(\s+\w+=)|>])/g
var reg = /<span\s+style=[\'\"]font-size\s*:\s*\d+pt;[\'\"]>/ig;
contentStyle=contentStyle.replace(reg4,'color="#FF0000">')
var index=contentStyle.indexOf('<b color="#FF0000">');
var num = 0; // 这个字符出现的次数
while(index !== -1) {
console.log(index); // 打印字符串出现的位置
let last=contentStyle.substring(index+1,contentStyle.length);
last=last.replace('</b>','</b></font>')
let bef=contentStyle.substring(0,index+1);
contentStyle=bef+last
num++; // 每出现一次 次数加一
index = contentStyle.indexOf('<b color="#FF0000">',index + 1); // 从字符串出现的位置的下一位置开始继续查找
}
contentStyle=contentStyle.replace(/<b color="#FF0000">/g, '<font color="#FF0000"><b> ')