I'm trying to figure out the regular expression that will match any character that is not a letter or a number. So characters such as (,,@,£,() etc ...
Once found I want to replace it with a blank space.
Any advice.
I'm trying to figure out the regular expression that will match any character that is not a letter or a number. So characters such as (,,@,£,() etc ...
Once found I want to replace it with a blank space.
Any advice.
To match anything other than letter or number you could try this:
[^a-zA-Z0-9]
And to replace:
var str = 'dfj,dsf7lfsd .sdklfj';
str = str.replace(/[^A-Za-z0-9]/g, ' ');
you are looking for:
var yourVar = '1324567890abc§$)%';
yourVar = yourVar.replace(/[^a-zA-Z0-9]/g, ' ');
This replaces all non-alphanumeric characters with a space.
The "g" on the end replaces all occurences.
Instead of specifying a-z (lower case) and A-Z (upper case) you can also use the in-case-sensitive option: /^[a-z0-9]/gi
.
This regular expression match not letters, digits, and underscores chars.
\W
For example in javascript:
"(,,@,£,() asdf 345345".replace(/\W/g, ' ');