Formula - replace
Replace a string with another string.
replace(oldText,newText,Content)
Formula function used to replace a specific char/word with another char/word, the result will contain the newText
instead of oldText
.
Quick example
Let's get you started with the following example: For other, and more advanced examples please scroll down on this page to the Examples section.
Input | Expression | Result |
---|---|---|
|
|
most innovative product |
Text Data | replace expression | Unique values |
Features
- Replace a given text from Content by a new text.
- Can be applied to any valid Content that return text; Like jsonpath, xpath functions, review Formula user guide for the complete list of functions.
Important
This plugin loads the entire message into RAM, so make sure to apply this function only on small messages.
How to use
To use the replace function, the Content parameter should contain a text/string (otherwise it will fail and you will end up with nothing). But first and foremost we have to configure the Formula plugin:
- Select Formula as the expression type plugin.
- Write down the expression to use in the 'Expression' text area.
- Input proper Content as a parameter to the function.
Syntax
Use the base64decode function with any of the following parameters:
From Message Body:
replace(oldText,newText,body)
From Message Context:
replace(oldText,newText,context('MessageContextKey'))
Result from previous Formula operation
replace(oldText,newText,SomeOtherNestedFormulaFunction(Content))
Examples
Below you will find different common examples of how to use the replace function.
Body as Content
"nodinite" is the body content, by using the provided expression, the result is The worlds most innovative product
.
e.g. replace('nodinite','The worlds most innovative product',body)
Message Body
nodinite
Expression
replace('nodinite','The worlds most innovative product',body)
Context as Content
"nodinite" is the Message Context value and the key is "id", by using the provided expression, the result is The worlds most innovative company
.
e.g. replace('nodinite','The worlds most innovative company',context('id'))
Message Context Value
nodinite
Expression
replace('nodinite','The worlds most innovative company',context('id'))
Formula Function as Content
Body content is json array and the Content parameter is jsonpath function, by using the provided expression, the result is Cool Function
, Cool Implementation
.
e.g. replace('Amazing','Cool',jsonpath('$..name',body))
Message Body
[
{ "name" :"Amazing Function"},
{"name" :"Amazing Implementation"}
]
Expression
replace('Amazing','Cool',jsonpath('$..name',body))
Next Step
How to Add or manage Search Fields
How to Add or manage Log Views
Related
Expression Type Plugins are used in Search Fields
What are Search Fields?
What are Search Field Expressions?
What are Message Types?
What are Log Views?