---
title: "text.findReplace: Find and replace — Note kit command — Kition"
description: "Replaces matches of `find` in the note's body with `replace` (matches in the front matter are not counted: change properties with `property.set`): the first by default, the n-th with `occurrence`, or every one with `occurrence: \"all\"`; `regex` and `caseSensitive` as in `text.find`. Answers how many were replaced."
canonical: "https://developer.kition.ai/docs/kits/note/commands/text.findReplace"
---

> Canonical HTML: [https://developer.kition.ai/docs/kits/note/commands/text.findReplace](https://developer.kition.ai/docs/kits/note/commands/text.findReplace)

# text.findReplace

**Find and replace.** Replaces matches of `find` in the note's body with `replace` (matches in the front matter are not counted: change properties with `property.set`): the first by default, the n-th with `occurrence`, or every one with `occurrence: "all"`; `regex` and `caseSensitive` as in `text.find`. Answers how many were replaced.

- Kit: Note 0.3.0 (Markdown (.md)); reference: [Note kit commands](https://developer.kition.ai/docs/kits/note.md)
- Changes the document: yes

## Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `caseSensitive` | `boolean` | no | Match case. |
| `find` | `string` | yes | The text, or a regular expression with regex. |
| `occurrence` | `any` | no | Which match to replace: a number from 1, or "all"; 1 by default. |
| `regex` | `boolean` | no | Read find as a regular expression (Rust syntax). |
| `replace` | `string` | yes | The replacement; with regex, $1 names a group. |

## Call through note_run

```text
note_run {
  "path": "<file>.md",
  "steps": [{ "command": "text.findReplace", "params": { "find": <string>, "replace": <string> } }]
}
```

The required parameters, with placeholders for their types: not a tested example. Optional: `caseSensitive`, `occurrence`, `regex`. note_run answers the step’s result in `completed[i].result`.

## Result

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `changed` | `boolean` | yes | Whether the note's text changed. |
| `replaced` | `integer` | yes | How many matches were replaced. |

```json
{
  "additionalProperties": false,
  "properties": {
    "changed": {
      "description": "Whether the note's text changed.",
      "type": "boolean"
    },
    "replaced": {
      "description": "How many matches were replaced.",
      "type": "integer"
    }
  },
  "required": [
    "changed",
    "replaced"
  ],
  "type": "object"
}
```

## Parameter schema

```json
{
  "additionalProperties": false,
  "properties": {
    "caseSensitive": {
      "default": true,
      "description": "Match case.",
      "type": "boolean"
    },
    "find": {
      "description": "The text, or a regular expression with regex.",
      "type": "string"
    },
    "occurrence": {
      "description": "Which match to replace: a number from 1, or \"all\"; 1 by default."
    },
    "regex": {
      "description": "Read find as a regular expression (Rust syntax).",
      "type": "boolean"
    },
    "replace": {
      "description": "The replacement; with regex, $1 names a group.",
      "type": "string"
    }
  },
  "required": [
    "find",
    "replace"
  ],
  "type": "object"
}
```

Generated from kition-sdk packages/script/kits/note.ts and the kit itself (kition-note@69e14d9).
