Reputation: 635
I'm currently doing the following to remove extraneous characters and quotes from my strings:
console.log(word);
word = word.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
console.log(word);
word = word.replace(/["']/g, "");
console.log(word);
Many words are being scanned, but my output tends to be:
“If
“If
"If
OR
time,”
time”
time”
Is my regex wrong?
Upvotes: 0
Views: 94
Reputation: 9690
I think the easiest way to solve this would be to use the following, instead:
word = word.replace(/[^\w\s]/g, '');
[^ ... ]
- inverted selection
\w
- matches alphanumerics, regardless of case
\s
- matches spaces
Upvotes: 1