我意识到我不能将一个空的正则表达式与/(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控制台中)
https://stackoverflow.com/questions/16600034
复制相似问题