---
schema_version: "1"
id: e5bc86727fa9946e0dd688849c97dcc9bc8280818cdbf9e653636b754d1794c1
title: REGEXP_SUBSTR
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/scalar-func/string-matching/regexp-substr.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/regexp-substr.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 753e140db4c7090b027006aeefb1f5841b4e70b8d5c807ef9375b37ac3073905
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# `REGEXP_SUBSTR`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Returns the substring matching a regular expression pattern.

## Syntax

```sql
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](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/string-matching.md#regular-expression-syntax).

## Examples

### Extract Digits

Extract a sequence of digits from a string.

```sql
SELECT regexp_substr('abc123def', '\d+') AS result;
```

Returns `'123'`.

### No Match

Returns NULL when pattern is not found.

```sql
SELECT regexp_substr('abcdef', '\d+') AS result;
```

Returns `NULL`.

### Extract Email Domain

Extract the domain from an email address.

```sql
SELECT regexp_substr('user@example.com', '@(.+)$') AS result;
```

Returns `'@example.com'`.

### Extract Words

Extract a word pattern.

```sql
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.

```sql
SELECT coalesce(regexp_substr(text, '\d+'), '0') AS number
FROM data;
```

Returns the matched digits or '0' if none are found.

## Related Documentation

- [SUBSTRING](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/string-func/substring.md)
- [REGEXP_INSTR](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/regexp-instr.md)
- [REGEXP_REPLACE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/regexp-replace.md)
- [Regular Expression Syntax](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/string-matching.md#regular-expression-syntax)
