Regular Expression: Any character that is NOT a letter or number

前端 未结 9 839
花落未央
花落未央 2020-12-07 19:32

I\'m trying to figure out the regular expression that will match any character that is not a letter or a number. So characters such as (,,@,£,() etc ...

Once found I

相关标签:
9条回答
  • 2020-12-07 20:16

    To match anything other than letter or number or letter with diacritics like é you could try this:

    [^\wÀ-úÀ-ÿ]
    

    And to replace:

    var str = 'dfj,dsf7é@lfsd .sdklfàj1';
    str = str.replace(/[^\wÀ-úÀ-ÿ]/g, '_');
    

    Inspired by the top post with support for diacritics

    source

    0 讨论(0)
  • 2020-12-07 20:19

    This is way way too late, but since there is no accepted answer I'd like to provide what I think is the simplest one: \D - matches all non digit characters.

    var x = "123 235-25%";
    x.replace(/\D/g, '');

    Results in x: "12323525"

    See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

    0 讨论(0)
  • 2020-12-07 20:22

    Just for others to see:

    someString.replaceAll("([^\\p{L}\\p{N}])", " ");
    

    will remove any non-letter and non-number unicode characters.

    Source

    0 讨论(0)
提交回复
热议问题