Skip to content

Access named groups from --js code to close #825 - #832

Merged
mathiasrw merged 16 commits into
mainfrom
fix/825
Oct 23, 2026
Merged

mathiasrw merged 16 commits into
mainfrom
fix/825

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #825

Stacked on #831.

Change

  • A named group is now a variable with rr_ in front: rr_year for (?<year>…), and rr_year_ has a space at the end. Before it was _year, which could clash with what RexReplace uses itself: a group named _require_ broke r().
  • With --js, a named group can not end with _, as rr_a_ would be both the group a_ and the group a with a space. It is a panic:
> echo -n 1x | rexreplace '(?<a>\d)(?<a_>\w)' 'rr_a' --js
 ❌ A named group can not end with _: a_
    No further processing.

Without --js there are no variables, so such a name is fine there.

The help and the README say rr_year. The tests of #799 and #815 use rr_.

Tests

test/fix/825.test.js is new. yarn test-ci passes.

After the review of 24 October

Follow-up

  • The help says it shorter: "Access a named group via the name prepended with rr_. (?<year>...) gives you rr_year. A named group name can not end with _." The README line is in Update README regarding --quiet, --debug, --simulate, --sort etc. to close #821 #838.
  • test/fix/825.test.js now covers names in uppercase, with a number and with $, two names that only differ by case, the cousin with a space, a name next to its $1, that _year is gone, and the panic for a_, Year_, _ and y2_ with a file that is not changed. 13 of its 15 tests fail without the fix.

@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 13:17
@mathiasrw
mathiasrw added this pull request to stack #841 October 23, 2026 13:56
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 15:08
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 15:13
@mathiasrw
mathiasrw removed this pull request from stack #841 October 23, 2026 15:57
@mathiasrw
mathiasrw added this pull request to stack #849 October 23, 2026 16:12
@mathiasrw
mathiasrw removed this pull request from stack #849 October 23, 2026 16:12
@mathiasrw
mathiasrw added this pull request to stack #850 October 23, 2026 16:17
@mathiasrw
mathiasrw removed this pull request from stack #850 October 23, 2026 16:47
@mathiasrw
mathiasrw added this pull request to stack #853 October 23, 2026 16:51
Base automatically changed from fix/815 to main October 23, 2026 16:54
@mathiasrw mathiasrw changed the title Use the prefix rr_ for named groups in --js, and panic on a name that ends with _ to close #825 Access named groups from --js code to close #825 Oct 23, 2026
@mathiasrw
mathiasrw merged commit f34b3c4 into main Oct 23, 2026
7 checks passed
@mathiasrw
mathiasrw deleted the fix/825 branch October 23, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the prefix rr_ for named groups in --js, and panic on a name that ends with _

1 participant