string.indexOfRegex()

Get the index of the matching String given a regex.

Signature

indexOfRegex(regex: String) => Number | Null

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

Description

Gets the index in the source string that matches regex, starting at index.

Parameters

Parameter Type Required Description

regex

String

Yes

Regex to match against the source string.

index

Number

Source string location to start matching against regex.
default = 0

Return value

Type Description

Number

Index of match with regex.

Null

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!