string.replaceAll()

Replace all occurrences of a substring in a String.

Signature

replaceAll(pattern: String, replacement: String) => String

Description

Replaces all occurrences of a provided substring in the calling String with a provided replacement.

Returns a new String. The calling String isn’t changed.

Parameters

Parameter Type Required Description

pattern

String

true

Substring to match in the calling String.

replacement

String

true

Replacement for matching substrings in the calling String.

Return value

Type Description

String

Resulting String with replacements.

Examples

'foobar'.replaceAll('foo', 'bar')
"barbar"
\