Suggest adopting .NET/Perl regexp named capture syntax
Lars Hansen
lhansen at adobe.com
Wed Oct 24 12:20:00 PDT 2007
> -----Original Message-----
> From: es4-discuss-bounces at mozilla.org
> [mailto:es4-discuss-bounces at mozilla.org] On Behalf Of StevenLevithan
>
> >> One other question... can the results from named capture be used in
a
> >> replacement closure function? I.e., will you be able to do
something
> >> like str.replace(/(?P<name>)/,function(match){return match.name;});
?
> >
> > The captured substrings with names are available as properties on
the
> > match result object, so that should work, yes.
>
> But the match result object is not available within a
> replacement closure function, hence the question.
Sorry, brain fart on my part. Interesting point. Will look into it;
expect another ticket tomorrow.
--lars
> At least in
> ES3, arguments[0] is a string primitive containing the entire
> match (i.e. backreference zero). It could be changed to a
> String object and have the named backreferences attached to
> it as properties (which is how I handle the issue in my
> http://stevenlevithan.com/regex/xregexp/ XRegExp library),
> but this is fundamentally a different thing, and might have
> some obscure potential for compatibility issues.
More information about the Es4-discuss
mailing list