Skip to content

splitParts - Split and capture a token in one command

We often split string values in order to capture some consistent parts. For example, we split chris@coralogix.com on @ to capture the domain, coralogix.com. splitParts does two things in one. The first is it splits a string on some delimiter value. The second is it returns the Nth token.

Note

index counts from 1, not from 0.

Syntax

Like many functions in DataPrime, splitParts supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

splitParts(string: string, delimiter: string, index: number): string
string: string.splitParts(delimiter: string, index: number): string

Arguments

NameTypeRequiredDescription
stringstringtrueThe string to split
delimiterstringtrueThe deliter on which to split the string
indexnumbertrueThe index of the desired split strings.

Example - Capturing domain from email

Consider the following document:

{
    "email": "chris@coralogix.com"
}

If I want to extract the domain from this email, I can do it in one line, using the splitParts function.

create domain from splitParts(email, '@', 2)
create domain from email.splitParts('@', 2)

This results in the following document:

{
    "email": "chris@coralogix.com",
    "domain": "coralogix.com"
}

Try it yourself

Open up your log explore screen and run the following command:

create email from 'chris@coralogix.com'
| create domain from email.splitParts('@', 2)