Regex: How should backreferences contained in the capturing match they reference to work?

StevenLevithan steves_list at
Mon Nov 26 01:08:42 PST 2007

liorean wrote:
>> I think I can sum up the change I think is appropriate by these things:
>> - undefined should be a failure to match instead of a match to the empty
>> string
>> - captures should only be set to undefined in two cases - when the
>>   regex matching is started, and if inside a negative lookahead

I am in complete agreement with liorean. The ES3 handling on these points is
non-intuitive, non-compatible with other regex libraries, *far* less useful
than the alternative (I could give countless examples of where the
Perl-style handling has real-world practicality), and creates future
compatibility issues if ECMAScript were to implement certain features from
Perl or other Perl-derivative flavors such as capturing-group-based

Lars T Hansen wrote:
>> I hope I'm not being overly flip when I say that it is the spec that
>> circumscribes the set of expectations you are allowed to have.  And
>> the spec is entirely clear here, ie what it says is not in question,
>> even if it's not always easy to find out what it says.  A somewhat
>> determined developer who needs to rely on the behavior can discover
>> what behavior is expected (though he obviously can't trust the
>> implementations to get it right).

I consider ES3's handling of capturing group participation and so forth
(summed up by liorean) to be bugs in the spec (perhaps I'm being overly
flip, but these are my biggest gripes with ES3 regexes). The fact that I
consider them bugs which might be fixed in future versions means that I
cannot rely on the behavior even though I understand what the spec

View this message in context:
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at

More information about the Es4-discuss mailing list