# `regexpSplitParts`

## Description

Splits a string using a regular expression as the delimiter and return the token at the specified index. The index starts at 1, not 0.

## Syntax

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

```dataprime
regexpSplitParts(value: string, delimiter: regexp, index: number): string
```

```dataprime
(value: string).regexpSplitParts(delimiter: regexp, index: number): string
```

## Arguments

| Name      | Type   | Required | Description                                  |
| --------- | ------ | -------- | -------------------------------------------- |
| value     | string | **true** | The string to split                          |
| delimiter | regexp | **true** | The regular expression used as the delimiter |
| index     | number | **true** | The 1-based index of the token to return     |

## Example

**Extract a value from inconsistently spaced key-value data**

Consider the following document:

```json
{
    "values": "val=4 val2=8  val3=9   val4=10"
}
```

Use `regexpSplitParts` with a whitespace pattern to split the string and return the third token:

### Example query

```dataprime
create val from regexpSplitParts(values, /\s+/, 3)
```

```dataprime
create val from values.regexpSplitParts(/\s+/, 3)
```

### Example output

```json
{
    "values": "val=4 val2=8  val3=9   val4=10",
    "val": "val3=9"
}
```
