RegExp free-spacing & comments
Caitlin Potter
caitpotter88 at gmail.com
Fri Nov 6 18:26:01 UTC 2015
Using that argument, you could say “well, we’ve already got StringLiterals, so we don’t need RegularExpressionLiterals” — And yet in reality, RegularExpressionLiterals are the most common way to actually use RegularExpressions. There’s a reason for that: it’s more concise, it’s identifiably a regular expression, it doesn’t have to worry about the RegExp constructor being overwritten or deleted, there’s no need to escape characters, or worse, use a horrible idea like tagged templates.
With the RegExp constructor, since you’re passing in a string, you can essentially add comments anyways by just terminating the string and commenting after it, so this isn’t really adding anything novel.
```javascript
let re = RegExp([
“(\\d{3} <smb://d%7B3%7D>-)?”, // Area Code
“(\\d{3}- <smb://d%7B3%7D->)”, // Exchange
“(\\d{4} <smb://d%7B4%7D>), // Line
].join(“”);
```
Template strings don’t really add anything special here — but nobody wants to write code like this anyways :)
> On Nov 6, 2015, at 1:07 PM, C. Scott Ananian <ecmascript at cscott.net> wrote:
>
> We have a template string mechanism, and it allows linefeeds. Let's
> use that, instead of inventing new heredoc syntax.
> --scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151106/946c25a9/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151106/946c25a9/attachment-0001.sig>
More information about the es-discuss
mailing list