REGEXP_SUBSTR

functionsupportedCore SQL functions

docs.snowflake.com ↗

String functions (regular expressions)

Returns the substring that matches a regular expression within a string.

Syntax

supportedpartialnot supportednot scored

REGEXP_SUBSTR( <subject> ,
               <pattern>
                 [ , <position>
                   [ , <occurrence>
                     [ , <regex_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
group_numoptionalSpecifies 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' is implied. Snowflake supports up to 1024 groups. For examples that use group_num, see the Examples in this topic.

Returns

The function returns a value of type VARCHAR that is the matching substring. When the 2026_04 BCR bundle is enabled and the subject is collated, the subject’s collation propagates to the return value; apply COLLATE '' to the subject to get an uncollated result. The function returns NULL in the following cases: - No match is found. - Any argument is NULL.

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.