Skip to content

Add --literal-replacement to use replacement as-is to close #798 - #802

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

mathiasrw merged 1 commit into
mainfrom
fix/798

Conversation

@mathiasrw

Copy link
Copy Markdown
Owner

Closes #798

Stacked on #801.

Change

--literal-replacement (-l): the replacement is used as it is. Without it, $1, $& and the other $ signs mean the groups and the match, as in javascript.

> echo -n PRICE | rexreplace '(PRICE)' 'only $1.99' -l
only $1.99
  • It is the last layer of the replacement, so it works the same for a typed replacement and one from --replacement-pipe.
  • The value of --js code is already used as it is, so the flag changes nothing there.
  • -l is taken from --nl, which keeps its long name. --nl came after 7.1.14, so nothing breaks. -L is the literal pattern and -l the literal replacement.

Tests

yarn test-ci passes: the demo on Node and Bun (with --literal-replacement), and 981 Bun tests. test/engine/literal-replacement.test.js is new.

@mathiasrw
mathiasrw added this pull request to stack #787 October 23, 2026 09:45
@mathiasrw
mathiasrw force-pushed the fix/798 branch 2 times, most recently from 0da17b0 to d9911ee Compare October 23, 2026 10:06
Base automatically changed from fix/797 to main October 23, 2026 10:08
@mathiasrw mathiasrw changed the title Add --literal-replacement to use the replacement as it is to close #798 Add --literal-replacement to use replacement as-is to close #798 Oct 23, 2026
@mathiasrw
mathiasrw merged commit 767ace4 into main Oct 23, 2026
7 checks passed
@mathiasrw
mathiasrw deleted the fix/798 branch October 23, 2026 10:24
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.

Add --literal-replacement to use the replacement as it is

1 participant