I want to remove(technically replacing) the words int, float, char, bool, main, void main, int main, cout, cin to "" (like removing it) if it is found on the string.
So if i have the ff:
str = "void main(){ couts<<"wrong"; cout<<"right"; }"
After replacing, it should be:
str = "(){ (); couts<<"wrong"; <<"right"; }"
The words int, float, char, bool, main... etc are stored inside an array
kWord[0] = /int/
kWord[1] = /float/
kWord[2] = /char/
kWord[3] = /bool/
kWord[4] = /main/
kWord[5] = /void\s+main/
kWord[6] = /int\s+main/
kWord[7] = /cout/
kWord[8] = /cin/
This is related to my previous question How to remove a part of the string the fastest way but this time the words are in Array
.replace()on the string for each index in the array. Or just create a single RegExp with all the words.var re = new RegExp('\b(' + kWord.join('|') + '\b'));. But if they're already regexps, you can just loop through them. But they need\bat the ends, and thegmodifiers.