replace new line character javascript code example
Example 1: file system replace line js
var fs = require('fs')
fs.readFile(someFile, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var result = data.replace(/string to be replaced/g, 'replacement');
fs.writeFile(someFile, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
Example 2: javascript replace p tags with new line
str = str.replace(/<p>(.*)<\/p>/g, "$1\n");