Splits a string using a regular expression into an array of values.

Function Traits: Transformation

ParameterTypeRequiredDefaultDescription
asstringoptional_splitstring Emit selected attribute using this name.
bystringrequired  String or regular expression to split by.
field[a]stringoptional  Field that needs splitting.
indexnumberoptional  Emit only this index after splitting. Can be negative; -1 designates the last element.

[a] The argument name field can be omitted.

The parameter name for field can be omitted; the following forms are equivalent:

logscale
splitString("value")

and:

logscale
splitString(field="value")

splitString() Examples

Assuming an event has the @rawstring="2007-01-01 test bar" you can split the string into fields part[0], part[1], and part[2]:

logscale
...
| part := splitString(field=@rawstring, by=" ")

Assuming an event has the @rawstring:

accesslog
2007-01-01 test bar

You can split pick out the date part using:

logscale
...
| date := splitString(field=@rawstring, by=" ", index=0)

Assuming an event has the @rawstring

<2007-01-01>test;bar

You can split the string into attributes part[0], part[1], and part[2]. In this case, the splitting string is a regex specifying any one of the characters <, >, or ;

logscale
...
| part := splitString(field=@rawstring, by="[<>;]")

Split an event into multiple events by newlines. The first function splitString() creates @rawstring[0], @rawstring[1], ... for each line, and the following split() creates the multiple events from the array of rawstrings.

logscale
...
| splitString(by="\n", as=@rawstring)
| split(@rawstring)

Split the value of a string field into individual characters:

logscale
characters := splitstring(my_field, by="(?!\A)(?=.)")

Split the value of a string using case-insensitive regex:

logscale
characters := splitstring(my_field, by="(?i)(e
| encoded
| enc)")