REGEXP_INSTR

functionsupportedCore SQL functions

docs.snowflake.com ↗

String functions (regular expressions)

Returns 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

NameRequiredDescription
subjectrequiredThe string to search for matches.
patternrequiredPattern to match. For guidelines on specifying patterns, see String functions (regular expressions).
positionoptionalNumber 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)
occurrenceoptionalSpecifies 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
optionoptionalSpecifies 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_numoptionalThe 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

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.