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

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

    If you mean "non-alphanumeric characters", try to use this:

    var reg =/[^a-zA-Z0-9]/g      //[^abc]
    
    0 讨论(0)
  • 2020-11-27 12:13

    This regex works for C#, PCRE and Go to name a few.

    It doesn't work for JavaScript on Chrome from what RegexBuddy says. But there's already an example for that here.

    This main part of this is:

    \p{L}

    which represents \p{L} or \p{Letter} any kind of letter from any language.`


    The full regex itself: [^\w\d\s:\p{L}]

    Example: https://regex101.com/r/K59PrA/2

    0 讨论(0)
  • 2020-11-27 12:15

    This should do it:

    [^a-zA-Z\d\s:]
    
    0 讨论(0)
提交回复
热议问题