I have a string that looks like this:
var string = 'Size? [Small] Color? [Blue]'
I want to remove all non alphanumeric but keep spaces and []
The end string would be
'Size [Small] Color [Blue]'
I tried the \W like this:
string = string.replace(/\W/g, '')
But that gets rid of the spaces and the []
I'm not sure how to exclude and include items in a regular expression?
string = string.replace(/[^a-zA-Z0-9 \[\]]+/g, '')