---
title: extractRegexGroups
description: |
  Return the positional capture groups of the first match of a regular
  expression, as an array of strings. A pattern that does not match returns
  `null`.

  Capture groups that are optional and did not take part in the match are
  returned as `null`.

  !!! note
      The pattern can't contain named capture groups. A named group fails the
      query with a `named capture group` error.
url: https://coralogix.com/docs/dataprime/language-reference/functions-reference/string/extractregexgroups/
product: dataengine
feature: DataPrime Language
feature_id: dataprime-language
feature_identifier: dataengine/dataprime-language
last_updated: '2026-12-01'
---

> Documentation index: https://coralogix.com/docs/llms.txt

# `extractRegexGroups`

## Description

Return the positional capture groups of the first match of a regular expression, as an array of strings. A pattern that does not match returns `null`.

Capture groups that are optional and did not take part in the match are returned as `null`.

> **Note:**
>
> The pattern can't contain named capture groups. A named group fails the query with a `named capture group` error.

## Syntax

Like many functions in DataPrime, `extractRegexGroups` supports [two notations](https://coralogix.com/docs/dataprime/language-reference/functions-reference.md), **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

**Function notation**

```dataprime
extractRegexGroups(value: string, pattern: regexp): array<string>
```

**Method notation**

```dataprime
(value: string).extractRegexGroups(pattern: regexp): array<string>
```

## Arguments

| Name      | Type     | Required | Description                                                                                                 |
| --------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------- |
| `value`   | `string` | **true** | The string to search                                                                                        |
| `pattern` | `regexp` | **true** | The regular expression to match. Capture groups can't be named. Must be a literal, not a dynamic expression |

## Example 1

**Use case: Split an IP address into its octets**

Groups are numbered by the order of their opening parenthesis, and the array follows that order.

### Example query

**Function notation**

```dataprime
create str from '192.168.1.1'
| create octets from extractRegexGroups(str, /(d+).(d+).(d+).(d+)/)
```

**Method notation**

```dataprime
create str from '192.168.1.1'
| create octets from str.extractRegexGroups(/(d+).(d+).(d+).(d+)/)
```

### Example output

```json
{
    "octets": ["192", "168", "1", "1"]
}
```

## Example 2

**Use case: Read a pair of values out of one field**

Every captured value is a string, so numeric captures need [\`convert\`](https://coralogix.com/docs/dataprime/language-reference/commands-reference/convert.md) before arithmetic.

### Example query

**Function notation**

```dataprime
create str from 'name=alice age=30'
| create parts from extractRegexGroups(str, /name=(w+) age=(w+)/)
```

**Method notation**

```dataprime
create str from 'name=alice age=30'
| create parts from str.extractRegexGroups(/name=(w+) age=(w+)/)
```

### Example output

```json
{
    "parts": ["alice", "30"]
}
```
