字符串数字加特殊样式
let str = 'haj123sdk54hask33dkhalsd879';
let str1 = 'haj123sdk54hask33dkhalsd879';
function findNum (str) {
return str.match(/\d+/g);
}
let arr2 = findNum(str).map(item => {
let st= "<span class='colorBlue'>" + item + "</span>"
str1 = str1.replace(item,st )
return str1
})
console.log(arr2[arr2.length-1])
// haj<span class='colorBlue'>123</span>sdk<span class='colorBlue'>54</span>hask<span class='colorBlue'>33</span>dkhalsd<span class='colorBlue'>879</span>
'haj123sdk54hask33dkhalsd879'.replace(/\d+/g,s => `<span class='highlight'>${s}</span>`)
全匹配
//下面的案例正则是将连续数字替换成字符串num
// RegExp(/\d+/g,'num')
let str =“12333”
//替换全部匹配内容:
let str2 =str.replace(/3/g,"2")