I am using this expression: /\W+/g to match all characters that are not numbers, letters and spaces. It seems to be including spaces. How would I build a regex that did not include spaces?
3 Answers
/[^a-z0-9\s]+/ig
Explanation:
[^ Character class which matches characters NOT in the following class
a-z All lowercase letters of the alphabet
0-9 All numbers
\s Whitespace characters
] End of the character class
i Case-insensitivity to match uppercase letters
5 Comments
chromedude
thanks, my guess is that I was not clear enough in my question, but all I needed to add to yours was
\s so what I found to work was /[^a-z0-9\s]+/igJeff
This regex still matches spaces, I think you want something like /[^a-z0-9\s]+/ig
IntelliData
@Tim Cooper - the regex still does not match spaces!
IntelliData
However, this works: /[^0-9a-zA-Z]/g as per this post: stackoverflow.com/a/24062304/3062486