Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 166a037

Browse files
authored
Merge pull request #6 from bakkot/patch-1
\k only changes semantics in the presence of named groups
2 parents 22142d2 + 54bed76 commit 166a037

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ An alternative possibility would be to provide named matches in a new `groups` o
7676

7777
### Backwards compatibility of new syntax
7878

79-
The syntax for creating a new named group, `/(?<name>)/`, is currently a syntax error in ECMAScript RegExps, so it can be added to all RegExps without ambiguity. However, the named backreference syntax, `/\k<foo>/`, is currently permitted in non-Unicode RegExps and matches the literal string `"k<foo>"`. In Unicode RegExps, such escapes are banned, however. Therefore, in this proposal, named backreferences are only permitted in Unicode RegExps.
79+
The syntax for creating a new named group, `/(?<name>)/`, is currently a syntax error in ECMAScript RegExps, so it can be added to all RegExps without ambiguity. However, the named backreference syntax, `/\k<foo>/`, is currently permitted in non-Unicode RegExps and matches the literal string `"k<foo>"`. In Unicode RegExps, such escapes are banned.
8080

81-
An alternative possibility would be to only allow named capture groups in Unicode RegExps, to avoid the hazard of a user thinking they had support but not realizing that backreferences were not permitted.
81+
In this proposal, `\k<foo>` in non-Unicode RegExps will continue to match the literal string `"k<foo>"` *unless* the RegExp contains a named group, in which case it will match that group or be a syntax error, depending on whether or not the RegExp has a named group named `foo`. This does not affect existing code, since no currently valid RegExp can have a named group. It would be a refactoring hazard, although only for code which contained `\k` in a RegExp.
8282

8383
## Precedent in other programming languages
8484

0 commit comments

Comments
 (0)