REGEXP_SUBSTR_ALL

functionsupportedCore SQL functions

docs.snowflake.com ↗

String functions (regular expressions)

Returns an ARRAY that contains all substrings that match a regular expression within a string.

Syntax

supportedpartialnot supportednot scored

REGEXP_SUBSTR_ALL( <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 ARRAY. The array contains an element for each matching substring. The function returns an empty array if no match is found. The function returns NULL in the following cases: - Any argument is NULL. - You specify group_num and the pattern doesn’t specify a grouping with that number. For example, if the pattern specifies only one group (for example, a(b)c), and you use 2 as group_num, the function returns 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.