The empty regular expressionAn empty regular expression matches everything.
> var empty = new RegExp(""); > empty.test("abc") true > empty.test("") trueAs you probably know, you should only use the RegExp constructor when you are dynamically creating a regular expression. But how do you create it via a literal, given that you can’t use // (the token that starts a line comment)? This is how:
> new RegExp("") /(?:)/
RegExp.prototypeInterestingly, the prototype object of regular expressions is also a regular expression, the empty regular expression:
> RegExp.prototype /(?:)/You can use RegExp.prototype like any other regular expression:
> "abc".match(RegExp.prototype) [ '', index: 0, input: 'abc' ]
The regular expression that matches nothingThe empty regular expression has an inverse – the regular expression that matches nothing:
> var never = /.^/; > never.test("abc") false > never.test("") false