> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# REGEXP_SUBSTR

> Returns the first substring matching a regular expression.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

Returns NULL for NULL value/pattern or when there is no match.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
regexp_substr(value, pattern)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRING | Yes | The string to search. |
| pattern | STRING | Yes | The regular expression. |

## Returns

* Type: STRING
* Possible values: The first full match (capture group zero).
* NULL behavior: Returns NULL for NULL value/pattern or when there is no match.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT regexp_substr('abc123def', '[0-9]+') AS "value", regexp_substr('abc', '[0-9]+') AS no_match;
```

| value | no\_match |
| - | - |
| 123 | NULL |

### Return the first matching word

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT regexp_substr('12 red 34 blue', '[a-z]+') AS first_word;
```

| first\_word |
| - |
| red |

## Limitations

* Invalid regular expressions raise an execution error.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.