2011/6/3 Kyle Simpson <[email protected]>:
> 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
[email protected]
https://mail.mozilla.org/listinfo/es-discuss