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

前端 未结 9 2132
醉梦人生
醉梦人生 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:59

    Try this:

    [^a-zA-Z0-9 :]
    

    JavaScript example:

    "!@#$%* ABC def:123".replace(/[^a-zA-Z0-9 :]/g, ".")
    

    See a online example:

    http://jsfiddle.net/vhMy8/

提交回复
热议问题