Extracts a group that matches the java-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 java documentation.


REGEX_EXTRACT ( 'string' , 'regex' , group )



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 a regular expression group number, defining which portion of the matching string to return. group 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_EXTRACT returns varchar.

Returns NULL if any one of the arguments is NULL.

If string is not of type varchar(max) or nvarchar(max), REGEX_EXTRACT 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 REGEXP_EXTRACT('1234567____123456', '\d{7}',0);

See Also#