Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API
Returns the substring matching a regular expression pattern.
Syntax
regexp_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
- Returns the first match when multiple matches exist.
- For detailed regex syntax, see Regular Expression Syntax.
Examples
Extract Digits
Extract a sequence of digits from a string.
SELECT regexp_substr('abc123def', '\d+') AS result;
Returns '123'.
No Match
Returns NULL when pattern is not found.
SELECT regexp_substr('abcdef', '\d+') AS result;
Returns NULL.
Extract Email Domain
Extract the domain from an email address.
SELECT regexp_substr('user@example.com', '@(.+)$') AS result;
Returns '@example.com'.
Extract Words
Extract a word pattern.
SELECT 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.
SELECT coalesce(regexp_substr(text, '\d+'), '0') AS number
FROM data;
Returns the matched digits or '0' if none are found.