user1881482
user1881482

Reputation: 746

Javascript regex to remove all punctuation except "." and "?"

I have been using a regex replace to remove all punctuation from a text box value and replace the whitespaces left by the removal. It is working great except I have realized I need it to leave . and ? in the field. Here is what I am currently using. How can I skip those two characters but remove all others?

script

var special = special.replace(/[^\w\s]|_/g, "").replace(/\s+/g, " ");

Upvotes: 0

Views: 1189

Answers (1)

Bergi
Bergi

Reputation: 664599

Just use [^\w\s?.] for your character class.

Upvotes: 5

Related Questions