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 Parameter | Type | Description |
---|---|---|
input | string | The input string to search. |
pattern | string | The regex match string |
flags (optional) | string | The modfier string. (Ex: combination of g, i, m) |
Return value
Type |
---|
number |
Sample
Example | Result | Description |
---|---|---|
regexSearch('Hi Fred', 'Fred') | 3 | Return first matched index for 'Fred' substring |
regexSearch('Hi Fred', 'fred') | -1 | Search for substring 'fred'. Return -1 if there is no match |
regexSearch('Hi Fred', 'fred', 'i') | 3 | Ignore case and search for substring 'fred' |
regexSearch('Hi! how are you 123', '\d') | 16 | Search for regex pattern - first matched digit |
regexSearch('Hi! how are you', '\d') | -1 | Return -1 if there is no match |
To view all the String functions, click here.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article