How do I remove the characters in a string that are included in another string?
let mustRemoved = "rin8cu73s9b";
let string = "CatsAndDogsAreAwesome"
Output Must Be : atAdDogAeAweome
What I have tried:
let regEx = new RegExp(mustRemoved, "ig");
let replaceMask = "";
let final = string.replace(regEx, replaceMask);
You can convert the string into an array of characters, filter out the characters which are included in mustRemoved, then join the resulting array.
let mustRemoved = "rin8cu73s9b".toLowerCase();
let string = "CatsAndDogsAreAwesome"
let res = [...string].filter(e => !mustRemoved.includes(e.toLowerCase())).join('')
console.log(res)
You need to change your regex so that it matches with every character in mustRemoved string, like this:
let mustRemoved = "rin8cu73s9b";
let string = "CatsAndDogsAreAwesome"
let regEx = new RegExp(mustRemoved.split('').join('|'), "ig");
let replaceMask = "";
let final = string.replace(regEx, replaceMask);
console.log(final)