replace
Replaces every occurrence of a substring with another throughout the string.
InputArgumentsReturns
SourcestringstringstringstringBehaviors
- Coerces scalars to text
- A scalar value such as a number or a boolean is converted to its text form before matching, so
42is 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 everyoneAll occurrencesSource
Replaces every match, not just the first.
Given
{"text": "banana"}Template
{{ text | replace:'a','o' }}Result
bononoNo matchSource
Leaves the value unchanged when the old substring is absent.
Given
{"text": "Hello"}Template
{{ text | replace:'xyz','abc' }}Result
HelloRemoveSource
Deletes the substring by replacing it with an empty string.
Given
{"text": "a b c"}Template
{{ text | replace:' ','' }}Result
abc