Default non-capturing regex flag [WAS: how to create strawmanproposals?]

Steven L. steves_list at
Sat Mar 17 21:31:51 PDT 2012

I'm seeing this for the first time now. Sorry for reviving old news.

On 2011-06-03, Brendan Eich wrote:

> Kyle Simpson wrote:
>> I propose a /n flag for regular expressions, which would swap the
>> default capturing/non-capturing behavior between ( ) and (?: )
>> operators (that is, ( ) would not capture, and (?: ) would capture).
> I like it.
> [...]
> As with all things RegExp, I wonder what Steve thinks.

I appreciate the vote of confidence! I consider /n to be a medium-strength 
nice-to-have. In fact, I added it myself in XRegExp v2.0.0-beta. [1]


Kyle called this the noncapturing flag and suggested 
RegExp.prototype.noncapturing. .NET calls the (?n) flag ExplicitCapture and 
does not let (?: ) capture. The reason for this is suggested by the name 
"explicit capture"--with /n, only explicitly named capturing groups of the 
form (?<name> ) capture a value. IMHO, this is the better way to go, but of 
course it's dependent on supporting named capture in the first place (as 
XRegExp does).

Also IMHO, it is better to shelve /n until named capture is added.

Mike Samuel wrote:

> Can RegExp flag experimentation be done in library code?

See [1].

--Steven Levithan


More information about the es-discuss mailing list