Searches for a string or regex pattern in the specified note and replaces it.
This action will throw an error if the specified note doesn't exist, so it's best to use it after the "Check For Existence Of Note" action has determined that it does exist.
Parameters
Vault
The vault to work in.
Type: Vault reference
Note Lookup
Specify which note should be looked up or manipulated by the action:
- "note": If you want to use another AFO action’s Note result, pick this option.
- "note at file path": The full path of the note, should be used if you already know the full file path (including folder and file extension).
- "note with UID": Use this if you are using unique identifiers for your notes, and you prefer to look them up by the UID.
- the current Periodic Note (daily, weekly, etc.)
Options:
- note
- note at file path
- note with UID
- Daily Note
- Weekly Note
- Monthly Note
- Quarterly Note
- Yearly Note
File Path
The path of the note, relative to the vault root.
Only available when Note Lookup is set to "note at file path".
Type: Text
UID
The unique identifier of the note. To configure the frontmatter key that is used for the lookup, go into Obsidian's settings, section "Community plugins", and find Actions URI.
Only available when Note Lookup is set to "note with UID".
Type: Text
Obsidian Note
A Note that was returned by another AFO action.
Only available when Note Lookup is set to "note".
Type: Note reference
Search term
Either a fixed string or a regular expression, depending on the value of Search term is a regular expression.
Regular expressions must be valid PCRE2 regex, e.g. /\d+/g
or /[abcd]+/gi
. See MDN or RegExr.com (unaffiliated) for info.
Type: Text
Replacement
The text to insert where the search term currently appears in your note.
Type: Text
Search term is a regular expression
By default, Search term is searched for as-is. With this option enabled, the search term is treated as a regular expression instead, and must follow the format /search term/
(trailing flags (g
, s
, i
, etc.) are allowed).
Type: Boolean (YES
/NO
)
Open or focus note
If enabled, after a successful operation, the note will be brought to the front in Obsidian.
Type: Boolean (YES
/NO
)
Examples
Suppose you have a note "Search and Replace demo.md" with the following content:
There's a number of options — and lot of fun to be had! 😉
Searching for a string and replacing with another string
With the search term Today
and the replacement Tomorrow
, the result will be:
Searching for a regular expression and replacing with a string
With a regex search term of /[oa]/ig
(meaning: all "o" or "a" characters, case-insensitive) and the replacement string ui
, the result is:
Searching for a regular expression and replacing with capture groups
Using regex together with capture groups is a powerful combination. For example, if a search term is /(my) (note)/
, and the note in questions contains "my note", then "my" and "note" will be available in the replacement as $1
and$2
, respectively.
Here's a concrete example: With a regex search term of /([oa])d([oa])/ig
(meaning: an "o" or "a" character followed by a "d" followed by an "o" or "a" character, case-insensitive) and the replacement string $2d$1
(meaning: the second capture followed by a "d" followed by the first capture), the result is:
Run it again:
Related Links
- Search the Actions for Obsidian community forum for "Search And Replace In A Note"