I need to replace all non alpha-numeric characters in a file name except for the period, I've been searching around and found close answers but not exact, here is what I narrowed it down to:
var temp = originalname.replace(/\W+/g, "_");
But this replaces everything, how can I exclude the period here (or any other characters if possible)?
You can use a negated character class:
var temp = originalname.replace(/[^\w.]+/g, "_");
[^\w.]+
will match 1 or more of any character that is not a word character and not a DOT.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With