I realized that I couldn't match an empty regex with /(regex here)/
syntax, because //
is a comment.
'this is a test'.match(//)
> SyntaxError: Unexpected token }
So, I tried new RegExp('')
and it worked:
'this is a test'.match(new RegExp(''))
> [""]
But when I checked the output of new RegExp('')
, it was this:
new RegExp('')
> /(?:)/
Why is this? (I am using Chrome version 26.0.1410.64 (Official Build 193017) m
and this is in the JavaScript console)