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

Kyle Simpson getify at gmail.com
Thu Jun 2 22:46:47 PDT 2011


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).

The /n property would reflect on the RegExp object as `Noncapturing == 
true`.


>>>> Is there any precedent for this in other perl-based regexp packages?
>>> ....Perl6....
>>> But more to the point of my intended proposal, .NET has the /n flag for 
>>> turning off capturing for ( ) -- I'm not sure if it then turns on 
>>> capturing for (?: ) or not, someone more familiar with .NET would have 
>>> to inform here.
>>
>> That's interesting. I found
>>
>> http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx
>> http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx#Explicit
>>
>> There is no sign of non-capturing syntax (?:...) here at all. This n flag 
>> seems a bit different from what you propose.
>
> http://msdn.microsoft.com/en-us/library/bs2twtah.aspx#noncapturing_group
>
> Again, I'm not sure if .NET swaps the default behavior as I'm proposing, 
> when /n is present. But it seems quite natural to me that /n would do so, 
> rather than having a strange asymmetry where without the flag, both 
> capturing and non-capturing are possible, but with the flag present *only* 
> non-capturing is possible.
>
>
>> As with all things RegExp, I wonder what Steve thinks.
>
> Do you mean Steven Levithan (aka "Mr Regex")? If so, he already commented 
> at length on that blog post I mentioned. I guess he implies the discussion 
> is worth having by saying "...and which can be explored in future 
> ECMAScript specs."


--Kyle

 



More information about the es-discuss mailing list