REGEXP_SUBSTR

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Returns the substring matching a regular expression pattern.

Syntax 

1regexp_substr(<string>, <pattern>)

Arguments 

Required 

  • <string>: The string to search within.
  • <pattern>: The regular expression pattern to match.

Returns 

Returns a text value containing the matched substring, or NULL if no match is found.

Considerations 

Examples 

Extract Digits 

Extract a sequence of digits from a string.

1SELECT regexp_substr('abc123def', '\d+') AS result;

Returns '123'.

No Match 

Returns NULL when pattern is not found.

1SELECT regexp_substr('abcdef', '\d+') AS result;

Returns NULL.

Extract Email Domain 

Extract the domain from an email address.

1SELECT regexp_substr('user@example.com', '@(.+)$') AS result;

Returns '@example.com'.

Extract Words 

Extract a word pattern.

1SELECT regexp_substr('Price: $99.99', '\$\d+\.\d+') AS result;

Returns '$99.99', because the digit string is considered a word.

Use with COALESCE 

Provide a default when no match.

1SELECT COALESCE(regexp_substr(text, '\d+'), '0') AS number
2FROM data;

Returns the matched digits or ‘0’ if none are found.

Related Documentation