javascript - Regular expression matching, replacing the content in html tags
某草草
某草草 2017-06-30 09:59:42
0
1
847

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>>

某草草
某草草

reply all(1)
phpcn_u1582
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)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template