Does \w also match numbers?

后端 未结 3 1527
失恋的感觉
失恋的感觉 2021-01-29 07:33

I would expect that this

var r = new RegExp(\'\\\\s\\\\@[0-9a-z]+\\\\s\', \'gi\');

applied to this string

1 @bar @foo2 * 112
         


        
3条回答
  •  生来不讨喜
    2021-01-29 08:21

    Yes, \w does match latin numbers. \w == [A-Za-z0-9_]

    Assuming you want to remove @fooX, you can use:

    console.log("1 @bar @foo2 * 112".replace(/\s@\w+/g, ""));

提交回复
热议问题