Better regexp literals!
const qr =// returns RegExp objectsqr`abc` // trueconst matches = 'this is a test' // matches === 'is '// regexp literals don't need backslash escapingqr`abc\s` // /abc\s/// add flagsqr`abc` // true// embeded variables get escapedconst foo = '[foo]'console // /\[foo]bar/qr`example` // equivalent of Perl qr/exam\Q\s\s\Eple/// embeded regexps are not escapedconst foo = /[foo]/console // /[foo]bar/
RegExp literals (
/like this/) are great. Except you can't embed other
vars in them. RegExp objects (
new RegExp('like this')) are flexible but
you have to escape your backslashes and that's annoying.
This gives you the best of both worlds. RegExp literal style syntax but with var embeding and escaping of your vars when you want them to be while still allowing you to easily compose multiple regexps together.
This is intended to provide the largely same functionality as the Perl regexp literals.
The primary difference from Perl is that embedded vars are escaped unless they're RegExp objects.