Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

string.replaceRegex()

Replace a specified number of occurrences of substrings matching a regular expression in a String.

Signature

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

replaceRegex(regex: String, replacement: String, amount: Number) => String

Description

Replaces the occurrences of substrings matching a regular expression in the calling String with a provided replacement for a specified number of times.

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

Parameters

Parameter Type Required Description

regex

String

true

Regular expression to match in the calling String. Supports Java regex.

replacement

String

true

Replacement for matching substrings in the calling String.

amount

Number

Number of replacements to make in the calling String. Defaults to 1.

Return value

Type Description

String

Resulting String with replacements.

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!