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

Lars T Hansen lth at acm.org
Thu Sep 13 10:03:31 PDT 2007


On 9/13/07, liorean <liorean at gmail.com> wrote:
> On 13/09/2007, Lars T Hansen <lth at acm.org> wrote:
> > The current behavior
> > is well-defined; it's not a hardship for anyone; the incompatibilities
> > among the engines are probably not a big deal (thus the incompatible
> > engines can be changed so that they conform); thus there is no
> > compelling reason to change the spec either.
>
> That the spec doesn't match expectations and that there are behaviours
> that do make sense to replace it with, coupled with the fact there
> seems to be no obvious compatibility problem with changing it
> (otherwise JScript and JavaScriptCore surely would have been changed
> to match the ES3 behaviour), makes no compelling reason?

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).

It's your contention that developers will be surprised by the current
behavior.  What can I say? Edge cases will always surprise somebody.
I don't feel surprised that captures are thrown away when a repeat
matcher repeats, even if you do.

Warnings are pointless on the web, and the language has no warnings
now.  If we're going to do something about backreferences inside their
own captures, it would have to be to outlaw them and require a syntax
error.

I doubt we're inclined to make any incompatible changes to the
matching algorithm, and (again) I don't really see the point.

(It is said a lawyer is a person who's not appaled by something if it
can be shown to be the consequence of a law.  I guess I'm a (language)
lawyer on this one :-)

--lars



More information about the Es4-discuss mailing list