Regular expression matching, replace the content in the html tag, excluding the content of the html tag itself;
For example:
var str="<p class='article'><p class=' article-item'>article-item</p></p>";
Matching keywords: article;
The desired matching result is:<p class="article"><p class="article-item"><span style="color:red">article</span>- item</p></p>>
phpcn_u15822017-06-30 10:01:42
var a="<p class='article'><p class='article-item'>article-item</p></p>".replace(/>([^<]*)<\//,function($0,$1){
var a=$1.split('-');
if(a.length>1){
return `><span style='color:red'>${a[0]}</span>-${a[1]}<`
}else{
return `>${a[0]}<`
}
})
console.log(a)