简体   繁体   中英

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, " ");

只需将[^\\w\\s?.]用于您的角色类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM