# regexp_match

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: regexp_match
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-functions/string-functions/regex/regexp-match
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/string-functions/regex/regexp-match.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/string-functions/regex/regexp-match.adoc
description: The `regexp_match()` function matches a POSIX regular expression pattern to a string.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/regex/regexp-match.md -->

The `regexp_match()` function matches a POSIX regular expression pattern to a string. It returns an array of `TEXT[]` type with substring(s) of matched groups within the first match.

## [](#syntax)Syntax

The syntax for `regexp_match()` function is:

```sql
REGEXP_MATCH(source_string, pattern, [flags])
```

## [](#parameters)Parameters

-   `source_string`: String on which to perform the match.

-   `pattern`: POSIX regular expression pattern to match.

-   `flags`: Optional. Flags that change the matching behavior of `regexp_match()`.


The `flags` parameter is an optional string that controls how the function operates. Here is a list of flags that are supported by Redpanda SQL:

-   `i`: Use this flag for case-insensitive matching.

-   `c`: Force case-sensitive matching (the default). Including `c` has the same effect as omitting all flags.


> 📝 **NOTE**
>
> If you specify multiple flags, the last one takes precedence. With `ci` the match is case-insensitive; with `ic` it is case-sensitive.

## [](#examples)Examples

### [](#basic-usage)Basic usage

These examples demonstrate how to find the first occurrence of an email address in the input string:

```sql
SELECT REGEXP_MATCH('Contact us at hello@example.com', '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}');
```

```sql
     regexp_match
----------------------
 {hello@example.com}
(1 row)
```

### [](#match-multiple-groups)Match multiple groups

The `regexp_match()` function can capture multiple groups within a match, which extracts key parts from a string in a structured way. This example shows how to extract the protocol, domain and path from a given URL:

```sql
SELECT REGEXP_MATCH('https://www.example.com/products/item123', '(https?)://([\w.-]+)/(.+)');
```

```sql
               regexp_match
------------------------------------------
 {https,www.example.com,products/item123}
(1 row)
```

### [](#case-insensitive-matching)Case-insensitive matching

This example shows how to match a pattern regardless of case-sensitivity:

```sql
SELECT REGEXP_MATCH('User.Name@Example.COM', '@([a-z0-9.-]+)$', 'i');
```

```sql
 regexp_match
---------------
 {Example.COM}
(1 row)
```

### [](#match-with-patterns-stored-in-a-table)Match with patterns stored in a table

This example shows how to take the source string and regex pattern directly from the table. First, create two sample tables:

```sql
CREATE TABLE users (
    email TEXT NOT NULL
);

CREATE TABLE patterns (
    id INT,
    regex_pattern TEXT NOT NULL
);
```

Once that is done, insert values into those tables:

```sql
INSERT INTO users (email) VALUES
    ('user@example.com'),
    ('admin@test.org'),
    ('invalid-email@wrong');

INSERT INTO patterns (id, regex_pattern) VALUES
    (0, '^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$');
```

Validate whether user emails in the `users` table are valid. If the regex doesn’t match, a `NULL` value is returned.

```sql
SELECT users.email,
       patterns.regex_pattern,
       REGEXP_MATCH(users.email, patterns.regex_pattern, 'i') AS is_valid
FROM users
JOIN patterns ON patterns.id = 0;
```

```sql
        email        |              regex_pattern              |   is_valid
---------------------+-----------------------------------------+--------------------
 user@example.com    | ^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$ | {user@example.com}
 admin@test.org      | ^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$ | {admin@test.org}
 invalid-email@wrong | ^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$ |
(3 rows)
```

### [](#restrictions)Restrictions

-   The function returns `NULL` if it cannot match the regular expression pattern.