replace
- Topics:
- Journeys
CREATED FOR:
- Experienced
- Developer
Replaces the first occurrence matching the target string by the replacement string in the base string.
The replacement proceeds from the beginning of the string to the end, for example, replacing “aa” with “b” in the string “aaa” will result in “ba” rather than “ab”.
Category
String
Function syntax
replace(<parameters>)
Parameters
Parameter | Type |
---|---|
base | string |
target | string (RegExp) |
replacement | string |
Signature and returned type
replace(<base>,<target>,<replacement>)
Return a string.
Example 1
replace("Hello World", "l", "x")
Returns “Hexlo World”.
Example 2
Because the target parameter is a RegExp, depending on the string you want to replace, you may need to escape some characters. Here is an example:
- string to evaluate:
|OFFER_A|OFFER_B
- provided by a profile attribute
#{ExperiencePlatform.myFieldGroup.profile.myOffers}
- String to be replaced:
|OFFER_A
- String replaced by:
''
- You need to add
\\
before the|
character.
The expression is:
replace(#{ExperiencePlatform.myFieldGroup.profile.myOffers}, '\\|OFFER_A', '')
The returned string is: |OFFER_B
You can also build the string to be replaced from a given attribute:
replace(#{ExperiencePlatform.myFieldGroup.profile.myOffers}, '\\|' + #{ExperiencePlatform.myFieldGroup.profile.myOfferCode}, '')
Journey Orchestration
- Product documentation
- What’s new
- Starting with Journey Orchestration
- Configuring an event
- Configuring a data source
- Configuring an action
- Using segments
- Building a journey
- Build expressions
- Building your reports
- Integrating with Intelligent Services
- Use cases
- Working with APIs