Reputation: 3
var fs = require('fs')
fs.readFile(someFile, 'utf8', function (err,data) {
var formatted = data.replace(/problem(.*)/gm, 'hiding this word');
fs.writeFile(someFile, formatted, 'utf8', function (err) {
if (err) return console.log(err);
});
});
for example if there is uppercase word like PROBLEM find the someFile.It should replace it with "hiding this word". Can anyone please help?
Upvotes: 0
Views: 25
Reputation: 23664
Just use the i
flag: /problem(.*)/gmi
let data = "Here is the pROblem";
let formatted = data.replace(/problem(.*)/gmi, 'hiding this word');
console.log(formatted)
Upvotes: 1