string.replaceRegex()

Replace occurrences of a String matching a regex.

Signature

replaceRegex(match: String, replacement: String) => String

replaceRegex(match: String, replacement: String, count: Number) => String

Description

The replaceRegex() method replaces count number of occurrences of the a string that evaluates to the match regex with the replacement string.

The original string isn’t changed.

Parameters

Parameter Type Required Description

match

String

Yes

Regex to compare against source string for matching string.

replacement

String

Yes

String to replace matching string in source string.

count

Number

Count of number of matching occurrences to replace.
default = 1.

Return value

Type Description

String

Original string with substrings that match the match regex replaced by the replacement string.

Examples

'foo bar'.replaceRegex('\\w', 'z', 2)
"zzo bar"

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!