I am trying to replace illegal characters from a file name using regular expression in javascript, but it continues to fall in IE 11 with "Syntax error in regular expression". The same code works fine in Chrome and Edge.
String.prototype.replaceAll = function (search, replacement) {
var target = this;
return target.replace(search, replacement);
};
var filename = 'test+&+this+again.2016.txt';
filename = filename.replaceAll(new RegExp(/[^a-zA-Z0-9_\-&.]+/, 'g'), '_');
Required conclusion
filename = 'test_&_this_again.2016.txt';
Any help would be greatly appreciated.
thank
source
share