- 2 minutes to read

Formula - replace

The replace Formula function returns the content with every occurrence of oldValue replaced by newValue.

Syntax

replace('oldValue', 'newValue', content)

Parameters

Parameter Required Description
'oldValue' Yes The text to find. It's matched as plain text, not as a pattern; use replaceregex for patterns.
'newValue' Yes The text to substitute. Use '' to remove oldValue.
content Yes The text to change: body, context, or the result of another function, such as jsonPath.

Returns

The content with all occurrences replaced. Content that doesn't contain oldValue is returned unchanged. When the content holds several values, the replacement runs on each value.

Examples

Example 1: Replace a word in the message body

Input

nodinite

Formula

replace('nodinite','The worlds most innovative product',body)

Result

The worlds most innovative product

Test Expression tab: replace on the message body nodinite returns The worlds most innovative product
The whole body matches oldValue, so the result is newValue only.

Example 2: Replace a word in a context property

Input

Key Value
id nodinite

Formula

replace('nodinite','The worlds most innovative company',context('id'))

Result

The worlds most innovative company

Test Expression tab: replace on the context value nodinite returns The worlds most innovative company
The value of the context property id is changed; the message body isn't used.

Example 3: Replace a word in several jsonPath values

Input

[{ "name": "Amazing Function" }, { "name": "Amazing Implementaion" }]

Formula

replace('Amazing','Cool',jsonPath('$..name', body))

Result

Cool Function
Cool Implementaion

Test Expression tab: replace on two jsonPath values returns Cool Function and Cool Implementaion
jsonPath returns two values, and replace changes Amazing in each one: two unique matches.

Next Steps