Contact Us 1-800-596-4880

replaceAll

replaceAll(text: String, target: String, replacement: String): String

Replaces all substrings that match a literal search string with a specified replacement string.

Replacement proceeds from the beginning of the string to the end. For example, the result of replacing "aa" with "b" in the string` "aaa" is "ba", rather than "ab".

Introduced in DataWeave version 2.4.0.

Parameters

Name Description

text

The string to search.

target

The string to find and replace in text.

replacement

The replacement string.

Example

This example shows how replaceAll behaves with different inputs.

Source

import * from dw::core::Strings
output application/json
---
{
    a: replaceAll("Mariano", "a" , "A"),
    b: replaceAll("AAAA", "AAA" , "B"),
    c: replaceAll(null, "aria" , "A"),
    d: replaceAll("Mariano", "j" , "Test"),
}

Output

{
   "a": "MAriAno",
   "b": "BA",
   "c": null,
   "d": "Mariano"
 }

replaceAll(text: Null, oldValue: String, newValue: String): Null

Helper function that enables replaceAll to work with a null value.

Introduced in DataWeave version 2.4.0.