- 使用正则替换字符串
原始数据:
2020-8-3 18:18:23
str.replace(new RegExp('-','g'),'.');
或
str.replace(/-/g,'.');
替换结果:
2020.8.3 18:18:23
- 使用正则替换HTML中的图片
原始数据:
hello world
let reg = new RegExp("
]*src=['\"]([^'\"]+)[^>]*>", "g");
html = html.replace(reg, function (match, capture) {
console.log(match)
console.log(capture)
return '
'
});
或者
html = html.replace(/
]*src=['"]([^'"]+)[^>]*>/gi, function(match, capture){
console.log(match)
console.log(capture)
return '
'
});
替换结果:
hello world