Suggest adopting .NET/Perl regexp named capture syntax

StevenLevithan steves_list at hotmail.com
Wed Oct 24 12:00:38 PDT 2007


Thanks for the feedback and for opening the ticket.


Lars T Hansen-2 wrote:
> 
>> 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.
> 
> --lars
> 

But the match result object is not available within a replacement closure
function, hence the question. 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.
-- 
View this message in context: http://www.nabble.com/Suggest-adopting-.NET-Perl-regexp-named-capture-syntax-tf4682705.html#a13390450
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com.




More information about the Es4-discuss mailing list