Gow_code
Gow_code

Reputation: 3

Replace case insensitive word with a line Javascript

    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

Answers (1)

Kinglish
Kinglish

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

Related Questions