tc39 / proposal-regexp-named-groups

Named capture groups for JavaScript RegExps
https://tc39.github.io/proposal-regexp-named-groups/
222 stars 21 forks source link

necessity of k in backreference over \<name> #28

Closed jnvm closed 6 years ago

jnvm commented 7 years ago

Numbered backreferences, the only current backreference, have no prefix character associated with them:

/f(o)\1/.test('foo')

This proposal gives named group backreferences a \k prefix before the <name>.

/f(?<x>o)(\k<x>)/.test('foo')

My suggestion is: why not just \<name>, without the k?

/f(?<x>o)(\<x>)/.test('foo')

As I see it:

The only arguments I can see against this are:

Is there a syntactic / functional reason the k needs to be there?

littledan commented 7 years ago

A couple reasons why I think \k< makes more sense than \<:

This proposal is at Stage 3, so I'd prefer to not make changes like this anymore unless the reason is very strong and clear-cut, leaving most changes to be based on implementation feedback.