Skip to content

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, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

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

Arguments

NameTypeRequiredDescription
valuestringtrueThe string to split
delimiterregexptrueThe regular expression used as the delimiter
indexnumbertrueThe 1-based index of the token to return

Example

Extract a value from inconsistently spaced key-value data

Consider the following document:

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

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

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

Output

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