sincecutoff.com
← all changes

Template `replace` function supports pattern replacement

Introduced 2026-05-07 · score 0.94

HOW TO USE IT

When formatting replacement text in a jj template, call `replace(pattern, content, replacement)`; use a lambda and `c.get(index)` to format text from regex capture groups.

jj log -T 'replace(regex:"(\\w+) (\\w+)", "hello world", |c| c.get(1) ++ " " ++ c.get(2))'

WHY THIS HELPS

Format replacement text while transforming string content in a jj template.

REQUIREMENTS AND LIMITATIONS

  • Version: v0.41.0
  • pattern (required): A `StringPattern`; `regex:"..."` matches substrings using a regular expression.
  • content (required): Template content in which to replace every pattern match.
  • replacement (required): A lambda of type `|RegexCaptures| -> Template`, formatted for each match.
  • RegexCaptures.get(index) (required): Returns the capture group at the given index; capture group 0 is the full match.
  • -T / --template (required): Passes a template expression to a jj command that accepts templates.
  • Prerequisite: Use jj v0.41.0 or later for the documented global `replace()` template function.
  • Supports all string patterns, including regexes with capture groups.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card