Skip to content

Give --js code the named groups to close #799 - #806

Merged
mathiasrw merged 1 commit into
mainfrom
fix/799
Oct 23, 2026
Merged

mathiasrw merged 1 commit into
mainfrom
fix/799

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #799

Stacked on #805.

Change

  • A named group is a variable in --js code, with rr_ in front: rr_year for (?<year>…). rr_year_ has a space at the end, like the other variables. The prefix keeps them apart from the other variables, so no name of a group can clash. (This PR used _ as the prefix. Access named groups from --js code to close #825 #832 changed it to rr_.)
> echo -n '2024-05' | rexreplace '(?<year>\d{4})-(?<month>\d\d)' 'rr_month + "/" + rr_year' --js
05/2024
  • A named group that took no part in the match is undefined.
  • When the code uses a named group, it runs once per match, like for $0 and $1.
  • Fix: with a named group in the pattern, the position of the match became an extra group variable ($3 was 0 with two groups). Now only the match and the groups get a variable, like --output-match already did.

Tests

yarn test-ci passes: the demo on Node and Bun, and 1019 Bun tests. test/fix/799.test.js is new.

@mathiasrw
mathiasrw added this pull request to stack #787 October 23, 2026 09:45
@mathiasrw
mathiasrw force-pushed the fix/799 branch 5 times, most recently from a2b4d9e to bf79ca7 Compare October 23, 2026 10:11
@mathiasrw
mathiasrw force-pushed the fix/799 branch 2 times, most recently from 2af1acb to 1a127f6 Compare October 23, 2026 10:48
Base automatically changed from fix/791 to main October 23, 2026 10:49
@mathiasrw
mathiasrw merged commit d2982bc into main Oct 23, 2026
7 checks passed
@mathiasrw
mathiasrw deleted the fix/799 branch October 23, 2026 11:01
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.

Give --js code the named groups, and fix an extra group variable

1 participant