我意识到我无法将空的正则表达式与/(regex here)/语法匹配,因为//它是一个注释。
'this is a test'.match(//)
> SyntaxError: Unexpected token }
所以,我试过new RegExp('')了,它奏效了:
'this is a test'.match(new RegExp(''))
> [""]
但是当我检查 的输出时new RegExp(''),是这样的:
new RegExp('')
> /(?:)/
为什么是这样?(我使用的是 Chrome 版本26.0.1410.64 (Official Build 193017) m,这是在 JavaScript 控制台中)