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

Brendan Eich brendan at mozilla.com
Mon Jun 6 10:03:21 PDT 2011


Escapes are a pain, due to the double-backslash burden.

We really want quasis for this kind of extensibility. Quasis solve the multiline problem too (I hope... :-).

/be

On Jun 6, 2011, at 9:52 AM, Mike Samuel wrote:

> 2011/6/3 Kyle Simpson <getify at gmail.com>:
>> 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`.
> 
> Can RegExp flag experimentation be done in library code?
> 
> function ExtRegExp(regexp, flags) {
>  if ("string" !== typeof regexp) {
>    // Convert parse tree form back to string
>  }
>  return RegExp(regexp, flags);
> }
> 
> ExtRegExp.parse = function (regexp) {
>  // Converts "^(?:foo|bar)$" to ["", ["^"], ["(?:)", ["|", "foo",
> "bar"]], ["$"]]
> };
> 
> ExtRegExp.n = function (regexp) {
>  // Converts "^(?:foo|bar)$" to ["", ["^"], ["(?:)", ["|", "foo",
> "bar"]], ["$"]]
>  if ("string" === typeof regexp) { regexp = ExtRegExp.parse(regexp); }
>  // Walk parse tree swapping "(?:)" nodes to capturing groups and vice-versa.
>  ...
>  return regexp;
> };
> 
> ExtRegExp.x = function (regexp) {
>  if ("string" === typeof regexp) { regexp = ExtRegExp.parse(regexp); }
>  // Walk parse tree eliminating whitespace.
>  ...
>  return regexp;
> };
> 
> // Use of n and x flags.
> 
> var myRegexp = new ExtRegExp(
>    ExtRegExp.n(
>        ExtRegExp.x(
>            "regexp-source-here")),
>    "i");
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list