REGEXP_EXTRACT

Extracts the first string in expression that matches the REGEXP expression and corresponds to the REGEX group index.

Syntax

REGEXP_EXTRACT(input string, regex string, expr_group_index integer) → string

  • input: The expression to search for a matching string.

  • regex: The Perl-compatible regular expression (PCRE) to match against.

  • expr_group_index: A regular expression group number, defining which portion of the matching string will be returned.

Examples

REGEXP_EXTRACT example
SELECT REGEXP_EXTRACT('100-500', '(\d+)-(\d+)', 1)
-- EXPR$0
  -- 100
REGEXP_EXTRACT example
SELECT REGEXP_EXTRACT('100-500', '(\d+)-(\d+)', 0)
-- EXPR$0
  -- 100-500

Last updated