REGEXP_INSTR
functionsupportedCore SQL functionsReturns the position of the specified occurrence of the regular expression pattern in the string subject. See also String functions (regular expressions).
Syntax
supportedpartialnot supportednot scored
REGEXP_INSTR( <subject> , <pattern> [ , <position> [ , <occurrence> [ , <option> [ , <regexp_parameters> [ , <group_num> ] ] ] ] ] )
Parameters
| Name | Required | Description |
|---|---|---|
subject | required | The string to search for matches. |
pattern | required | Pattern to match. For guidelines on specifying patterns, see String functions (regular expressions). |
position | optional | Number of characters from the beginning of the string where the function starts searching for matches. The value must be a positive integer. Default: 1 (the search for a match starts at the first character on the left) |
occurrence | optional | Specifies the first occurrence of the pattern from which to start returning matches. The function skips the first occurrence - 1 matches. For example, if there are 5 matches and you specify 3 for the occurrence argument, the function ignores the first two matches and returns the third, fourth, and fifth matches. Default: 1 |
option | optional | Specifies whether to return the offset of the first character of the match (0) or the offset of the first character following the end of the match (1). Default: 0 |
group_num | optional | The group_num parameter specifies which group to extract. Groups are specified by using parentheses in the regular expression. If a group_num is specified, Snowflake allows extraction even if the e option was not also specified. The e option is implied. Snowflake supports up to 1024 groups. For examples that use group_num, see Examples of capture groups in this topic. |
Returns
Returns a value of type NUMBER. If no match is found, returns 0.
Usage notes
- Positions are 1-based, not 0-based. For example, the position of the letter “M” in “MAN” is 1, not 0.
- For additional usage notes, see the General usage notes for regular expression functions.
Collation details
When the 2026_04 BCR bundle is enabled, the function accepts arguments with a collation specification. The collation has no effect on pattern matching: matching is always case-sensitive unless you pass the i flag in the parameters argument.