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.indexOfRegex()

Get the index of the first substring matching a provided regular expression within a String.

Signature

indexOfRegex(regex: String) => Number | Null

indexOfRegex(regex: String, start: Number) => Number | Null

Description

Returns the zero-based offset index for the first occurrence of a substring matching a provided regular expression within the calling String. Starts at an optional start position in the calling String. == Parameters

Parameter Type Required Description

regex

String

true

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

start

Number

Zero-based index of the character to start searching for matches. Defaults to 0.

Return value

Type Description

Int

Zero-based index of the first matching occurrence in the calling String.

Null

No match not found.

Examples

'foo 123'.indexOfRegex('[0-9]')
4
'foo 123 abc 5678'.indexOfRegex('[0-9]', 10)
12

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!