Regex, every non-alphanumeric character except white space or colon

前端 未结 9 2110
醉梦人生
醉梦人生 2020-11-27 11:23

How can I do this one anywhere?

Basically, I am trying to match all kinds of miscellaneous characters such as ampersands, semicolons, dollar signs, etc.

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 11:55

    In JavaScript:

    /[^\w_]/g

    ^ negation, i.e. select anything not in the following set

    \w any word character (i.e. any alphanumeric character, plus underscore)

    _ negate the underscore, as it's considered a 'word' character

    Usage example - const nonAlphaNumericChars = /[^\w_]/g;

提交回复
热议问题