regexSearch

Modified on Wed, 02 Aug 2023

Description

Return first index of match for `pattern` in `input` string. Return `-1` if there is no match.

Syntax

regexSearch(input, pattern, flags)

Parameters

Input ParameterTypeDescription
inputstringThe input string to search.
patternstringThe regex match string
flags (optional)stringThe modfier string. (Ex: combination of g, i, m)

Return value

Type
number

Sample

ExampleResultDescription
regexSearch('Hi Fred', 'Fred')3Return first matched index for 'Fred' substring
regexSearch('Hi Fred', 'fred')-1Search for substring 'fred'. Return -1 if there is no match
regexSearch('Hi Fred', 'fred', 'i')3Ignore case and search for substring 'fred'
regexSearch('Hi! how are you 123', '\d')16Search for regex pattern - first matched digit
regexSearch('Hi! how are you', '\d')-1Return -1 if there is no match

To view all the String functions, click here.