I have a string. I need to parse it, replacing any chars (except numbers (0 to 9),, and ..
How can I do it with javascript?
Tried with :
string.replace(/[a-zA-Z]*/, "");
but seems it doesnt works. Also, I need ANY chars, not only a-Z (also ?, /, white space, and so on, expect, as said, , and .
Use a negated character class
and put in any character you don’t want to be replaced, it will match all the others.
See it here on Regexr
You can optimize it by adding a quantifier
+, so that it replaces a sequence of those characters at once and not each by each.As Felix Kling pointed out, its important to use the global option
gto match on all occurrences of the pattern.See it here on Regexr