How to remove everything but letters, numbers, space, exclamation and question mark from string?
You can use regex myString.replace(/[^\w\s!?]/g,”); This will replace everything but a word character, space, exclamation mark, or question. Character Class: \w stands for “word character”, usually [A-Za-z0-9_]. Notice the inclusion of the underscore and digits. \s stands for “whitespace character”. It includes [ \t\r\n]. If you don’t want the underscore, you can use just [A-Za-z0-9]. … Read more