replace

Replaces every occurrence of a substring with another throughout the string.

InputArgumentsReturnsstringstringstringstring
Source

Behaviors

Coerces scalars to text
A scalar value such as a number or a boolean is converted to its text form before matching, so 42 is accepted as "42".
BasicSource

Replaces every occurrence of the old substring with the replacement.

Given

{"text": "Hello world"}

Template

{{ text | replace:'world','everyone' }}

Result

Hello everyone
All occurrencesSource

Replaces every match, not just the first.

Given

{"text": "banana"}

Template

{{ text | replace:'a','o' }}

Result

bonono
No matchSource

Leaves the value unchanged when the old substring is absent.

Given

{"text": "Hello"}

Template

{{ text | replace:'xyz','abc' }}

Result

Hello
RemoveSource

Deletes the substring by replacing it with an empty string.

Given

{"text": "a b c"}

Template

{{ text | replace:' ','' }}

Result

abc