RegExp free-spacing & comments

Gorkem Yakin goyakin at
Sat Nov 7 01:59:09 UTC 2015

I don’t know about other engines, but Chakra does cache the RegExp matcher when the RegExp object is created via the constructor.


From: es-discuss [mailto:es-discuss-bounces at] On Behalf Of Isiah Meadows
Sent: Friday, November 6, 2015 4:36 PM
To: C. Scott Ananian <ecmascript at>; Brian Terlson <Brian.Terlson at>
Cc: es-discuss at
Subject: Re: RegExp free-spacing & comments

The problem with using the RegExp constructor is that it is never cached by the engine. As a literal, engines usually internalize them, speeding up matches very quickly.

On Fri, Nov 6, 2015, 14:24 C. Scott Ananian <ecmascript at<mailto:ecmascript at>> wrote:
On Fri, Nov 6, 2015 at 1:20 PM, Brian Terlson
<Brian.Terlson at<mailto:Brian.Terlson at>> wrote:
> or similar seems nice:
> ```
> let re ="x")`
>     (\d{3}-)? # area code (optional)
>     \d{3}-    # prefix
>     \d{4}     # line number
> `;
> ```
> But it seems like previous proposals of this want escaping which doesn't seem ideal for this purpose. Do we need both `` and `RegExp.escapedRe`?

Escaping happens if you use interpolation into the string template:
let re =`(?x:
    (\d{3}-)?      # area code (optional)
    ${ /\d{3}/ }-  # prefix
    \d{4}           # line number
    ( ${ "*" } \d+ )?  # extension
If the interpolated expression is a regexp, then things seem
relatively straightforward (although there are corner cases to
consider).  If the interpolated expression is a string, then it is
suggested that you use some sort of automatic escaping.
es-discuss mailing list
es-discuss at<mailto:es-discuss at><>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list