javascript - Replacing URLs in html not working -
i want replace links in html file not working.
var fs = require('fs'); fs.readfile(__dirname + '/index.html', 'utf8', function(err, html){ if(!err){ html = html.replace('https://mysite1.github.io/', 'https://example.com/'); console.log(html); } else{console.log(err);} });
can u me this? i'm bit new in nodejs/javascript
replace
replaces first instance. need use regular expression replace all.
var fs = require('fs'); fs.readfile(__dirname + '/index.html', 'utf8', function(err, html){ if(!err){ var replacelink = "https://mysite1.github.io/"; var regex = new regexp(replacelink, "g"); html = html.replace(regex, "https://example.com/"); console.log(html); } else{console.log(err);} });
Comments
Post a Comment