RegExp free-spacing & comments
Gorkem Yakin
goyakin at microsoft.com
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.
Gorkem
From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Isiah Meadows
Sent: Friday, November 6, 2015 4:36 PM
To: C. Scott Ananian <ecmascript at cscott.net>; Brian Terlson <Brian.Terlson at microsoft.com>
Cc: es-discuss at mozilla.org
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 cscott.net<mailto:ecmascript at cscott.net>> wrote:
On Fri, Nov 6, 2015 at 1:20 PM, Brian Terlson
<Brian.Terlson at microsoft.com<mailto: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<mailto:es-discuss at mozilla.org>
https://mail.mozilla.org/listinfo/es-discuss<https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fmail.mozilla.org%2flistinfo%2fes-discuss&data=01%7c01%7cgoyakin%40microsoft.com%7c0ebaa0e85f994ffe3c0708d2e70b81db%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=g9mQNk%2bq0%2bD8%2bwq6NdZf95q9eWMoaq2OhvMhT3kwiRs%3d>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151107/92f72dd2/attachment-0001.html>
More information about the es-discuss
mailing list