RegExp free-spacing & comments

Caitlin Potter caitpotter88 at
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.

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

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> 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: <>
-------------- 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: <>

More information about the es-discuss mailing list