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

前端 未结 9 829
花落未央
花落未央 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:13

    Have you tried str = str.replace(/\W|_/g,''); it will return a string without any character and you can specify if any especial character after the pipe bar | to catch them as well.

    var str = "1324567890abc§$)% John Doe #$@'.replace(/\W|_/g, ''); it will return str = 1324567890abcJohnDoe

    or look for digits and letters and replace them for empty string (""):

    var str = "1324567890abc§$)% John Doe #$@".replace(/\w|_/g, ''); it will return str = '§$)% #$@';

提交回复
热议问题