Well, I thought this would be simple but I am having problems converting some PHP regex code to javascript.
Here is my JS code:
for(var i=0; i < badwords.length; i++) {
var badword = badwords[i].slice(0, -2);
var regex = "/(";
for(var j=0; j < badword.length; j++) {
regex += "[" + badword[j].toLowerCase() + "|" + badword[j].toUpperCase() + "][/W]*";
}
regex += ")/";
msg = msg.replace(new RegExp(regex, "g"), "");
}
I am not getting a match and no replacement is happening. This same code structure and regex format worked in a PHP application.
Any help is appreciated, thanks.
If your input is
foo, your regular expression should be/f[^a-z]*o[^a-z]*o/ig. You can build this regular expression using strings and regular expressions like this: