从 js 文件和 chrome 控制台运行时正则表达式产生不同的匹配

regexp resulting different matches when run from js file and chrome console

这很奇怪,我在 js 代码中有这样的语句:

alert ( "Hello @name , your account will be activated at  @date".match(/@{1}[\w_]+/g) );

当我从文件运行代码时(使用浏览器打开文件) 我得到

[hello,name,your,account,be,activated,date]

但是当我在 chrome 开发者控制台上运行它时
我得到:

[@name,@date]

这里发生了什么?相同的代码 d/t 结果

更新:

正如@funkwurm 试图在评论中提到的那样,当我使用 chrome 开发人员工具检查页面时,代码发生了变化。
match(/@{1}[\w_]+/g) 已更改为 match(/\[\w_]+/g)

我正在使用 Grails 框架,所以我认为使用 slashy syntax (/ /) 是导致问题的原因,因为 Grails 也使用它语法(由于冲突)。

所以改成了

var pattern = new RegExp("@{1}[\w_]+","g");    


alert ( "Hello @name , your account will be activated at @date".match(pattern) );

但仍然没有效果,当我这样做时 alert(pattern) 我得到 /\[\w_]+/g 仍然没有 @.

谢谢

正如我在 更新 中提到的那样 问题是使用 chrome 开发人员工具 [=26] 检查时缺少 @ 字符=](感谢 @Lee Kowalkowski 的见解)。

我试过转义,但还是不行。

这是我想出的解决方案:

var pattern = new RegExp(String.fromCharCode(64)+"{1}[\w_]+","g"); //64 is ascii value of @

仍然很想知道为什么@字符丢失