Is there an easy way to use JavaScript regular expressions to match a BOM? I'd like to build a utility that does this in Node.js, but the following doesn't seem to match anything:
fixBomFiles : function(offendingFiles) {
var i = 0,
file, js;
for (i=0; i < offendingFiles.length; i++) {
file = offendingFiles[i];
js = this.parent.fs.readFileSync(file, 'utf8');
js = js.replace(/\uFEFF/g, '');
this.parent.fs.writeFileSync(file, js, 'utf8');
}
}
Any ideas? I'm guessing my regular expression is bad, or I shouldn't be using UTF-8 encoding for read/write.
Derp... the RegEx was fine. My script was not correctly loading "offendingFiles".