First question on here so please be nice 🙂
I know very little about regular expressions but I am using one in a current project which strips special characters from a string. It looks like this…
newWord = newWord.replace(/[^0-9A-Za-z ]/g, '');
It works well, but I need to modify it slightly so that it doesn’t remove the £ (GBP) character.
I’ve tried several things but without learning regexes from the start I’m just guessing and none of it’s working.
Can anyone help?
or with unicode escape
What you are doing with this regular expression is removing any characters that are not in the list you are providing. The
minuscharacter is used to express a range, so any character not in 0-9 (0,1,2,3,..9) A-Z and a-z are replaced by nothing (”). By adding an £ it will no longer replace it with nothing.