Browse the docs

replace

Replaces every match of a regular expression in the text.

Details #

replace(text, pattern, replacement) takes exactly three arguments and returns text.

pattern is a regular expression (ICU syntax, as used by macOS). It is case-sensitive and every match is replaced. In replacement, $1, $2 and so on insert capture groups, and $0 the whole match. Use \$ for a literal dollar sign in the replacement.

To replace plain text, use characters that aren't special in a pattern, or escape them.

Parameters #

Takes 3 arguments. {{ replace(text, b, c) }}

Examples #

replace("2026-10-24", "([0-9]+)-([0-9]+)-([0-9]+)", "$3/$2/$1")
→ 24/10/2026
replace("a  b   c", " +", " ")
→ a b c
replace("a-b-c", "-", "_")
→ a_b_c

Gotchas #

  • A pattern that isn't valid stops the step: '(' isn't a valid regular expression.

  • Inside quotes a backslash followed by a letter drops the backslash ("\d" becomes d) except \n, \t and \r. Write "\\d" for the pattern \d, or use [0-9].