js 正则替换

var fs  = require('fs');


var fileDy="index.vue";
var str=fs.readFileSync(fileDy).toLocaleString();
console.log(str)
let re = /row1/gi;  

//var str = 'row1 are round, and apples are juicy.';  

var newstr = str.replace(re, 'row2');  

console.log(newstr)

fs.writeFile('index1.vue',newstr,function(err){
    if (err) { console.log('-----------error-------------') }
})
原文地址:https://www.cnblogs.com/cnchengv/p/11149364.html