首页 > 代码库 > js正则替换replace

js正则替换replace

content = "<p><strong>发斯蒂芬斯</strong>蒂芬434324</p><p><strong>范德萨发</strong>的发斯蒂芬</p><p><strong>242<b>3423</b>423</strong></p>";
console.log(content);
var pattern = /([\u4e00-\u9fa5]|[^<>])+(<[^>]+>)+([\u4e00-\u9fa5]|[^<>])+(<[^>]+>)/g;
content = content.replace(pattern,function($1){console.log($1);return $1.replace(/<[^>/]+>/g,‘‘)});//替换不规范文本
console.log(content);

技术分享

 

js正则替换replace