Extracts a group that matches the POSIX-style regular expression regex. A string function used in search operations for sophisticated pattern matching including repetition and alternation. For more information on the Java format for regular expressions see the POSIX documentation.


REGEX_SPLIT ( 'string' , 'regex' , element_index )



Is the string to search for strings matching the regular expression. ‘string’ can be of a character data type.


Is the regular expression to match. ‘regex’ can be of a character data type.


Is an element index, defining which element of the matching string to return. element_index can be of a integer data type.

Return types

Returns nvarchar if one of the input arguments is of the nvarchar data type; otherwise, REGEX_SPLIT returns varchar.

Returns NULL if any one of the arguments is NULL.

If string is not of type varchar(max) or nvarchar(max), REGEX_SPLIT truncates the return value at 8,000 bytes. To return values greater than 8,000 bytes, string must be explicitly cast to a large-value data type.


SELECT REGEX_SPLIT('1234567____123456', '\d{7}',0);

See Also