Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

replace

replace(String, Regex): ((Array<String>, Number) → String) → String

Replaces a section of a string for another, in accordance to a regular expression, and returns a modified string.

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
b: 'admin123' replace /(\d+)/ with 'ID'
Output

        
     
1
2
3
{
  'b': 'adminID'
}
replace(String, String): ((Array<String>, Number) → String) → String

Replaces the occurrence of a given string inside other string with the specified value.

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
b: "admin123" replace "123" with "ID"
Output

        
     
1
2
3
{
  "b": "adminID"
}