RegExp free-spacing & comments

Isiah Meadows isiahmeadows at gmail.com
Sat Nov 7 00:36:26 UTC 2015


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 cscott.net> wrote:

> On Fri, Nov 6, 2015 at 1:20 PM, Brian Terlson
> <Brian.Terlson at microsoft.com> wrote:
> > RegExp.re or similar seems nice:
> >
> > ```
> > let re = RegExp.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 `RegExp.re` and
> `RegExp.escapedRe`?
>
> Escaping happens if you use interpolation into the string template:
> ```
> let re = RegExp.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.
>  --scott
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151107/c02c1f7e/attachment.html>


More information about the es-discuss mailing list