{
  "slug": "template-replace-function-supports-pattern-replacement-09e80ed08fd7",
  "title": "Template `replace` function supports pattern replacement",
  "tools": [
    "jj"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-05-07T12:36:00.000Z",
  "announced_at": "2026-05-07T12:36:00.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "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.",
    "examples": [
      "jj log -T 'replace(regex:\"(\\\\w+) (\\\\w+)\", \"hello world\", |c| c.get(1) ++ \" \" ++ c.get(2))'"
    ],
    "gotchas": [
      "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."
    ]
  },
  "why_it_matters": "Format replacement text while transforming string content in a jj template.",
  "sources": [
    "https://github.com/jj-vcs/jj/releases/tag/v0.41.0",
    "https://github.com/jj-vcs/jj/blob/v0.41.0/docs/templates.md"
  ],
  "rank": 0.94022,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v2+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "wave1b-tools-20261017",
    "verdict_id": "wave1b-tools-20261017:wave1b-tools-20261017-6da253a5578c1bf6-7:gate",
    "evidence_hash": "e705ee9b9fa834ff6cba11a1155f4cc5e40b2ef96198803e26ccfaf2c23c0650"
  },
  "review": {
    "draft_hash": "4058b91edee50ffc42e626e0787089959fe3af42866312d3df2b7b19fbdbe032",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "wave1b-tools-20261017:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.94 >= 0.9; 2 needed) and Jev gave 0.67 (>= 0.6 needed)."
  }
}
