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 <ecmascr...@cscott.net> wrote: > On Fri, Nov 6, 2015 at 1:20 PM, Brian Terlson > <brian.terl...@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@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss