split
Use the split() function to divide a string into an array of substrings based on a specified delimiter.
Syntax
split (<value> [, <string_delimiter>])Parameters
value
string
Yes
The string field or literal value to split.
string_delimiter
string
No
The string literal used as the delimiter. If omitted or set to an empty string (""), a space (' ') is used by default.
Returns
The split() function returns an array of strings containing the substrings generated by splitting the input value.
Usage notes
The function operates exclusively on string inputs.
The delimiter itself is not included in the resulting array elements.
If the delimiter appears consecutively, or at the beginning or end of the string, it can result in empty strings as elements in the output array.
If the input
valueis NULL, the function returns an empty array[].
Examples
Example 1: Basic split with a specific delimiter
Goal: Split an IP address string by the dot (.) character to separate its octets.
XQL code:
Explanation: The function divides the ipv4_address string into an array of individual numeric octets using the specified . delimiter.
Output:
101
192.168.1.10
["192", "168", "1", "10"]
102
10.0.0.5
["10", "0", "0", "5"]
105
192.168.10.20
["192", "168", "10", "20"]
Example 2: Split without a specified delimiter
Goal: Split a log message into individual words using the default delimiter (space).
XQL code:
Explanation: By omitting the optional delimiter argument, the function automatically uses a space to break the raw_log_data string into an array of words.
Output:
101
User Alice logged in from 192.168.1.10
["User", "Alice", "logged", "in", "from", "192.168.1.10"]
102
Process cmd.exe attempted to access /etc/passwd
["Process", "cmd.exe", "attempted", "to", "access", "/etc/passwd"]
Example 3: Split with an empty string as delimiter
Goal: Explicitly use an empty string as the delimiter, which defaults to splitting by space.
XQL code:
Explanation: Providing an empty string "" for the delimiter results in the same behavior as omitting the delimiter; the string is split by spaces.
Output:
101
User Alice logged in from 192.168.1.10
["User", "Alice", "logged", "in", "from", "192.168.1.10"]
Example 4: Split on a delimiter not present in the string
Goal: Attempt to split a string using a delimiter that does not exist within that string.
XQL code:
Explanation: The function returns an array containing the original string as its single element because the pipe (|) character is not present in the event_description.
Output:
101
User login successful
["User login successful"]
Example 5: Split on a field containing NULL values
Goal: Handle input fields that contain NULL values.
XQL code:
Explanation: When the input string field (for example, dst_domain for event ID 105) is NULL, the function returns an empty array.
Output:
105
NULL
[]
Example 6: Combining split with arrayindex
Goal: Split a string and immediately extract a specific element from the resulting array.
XQL code:
Explanation: The query first uses split() to tokenize the ipv4_address. Subsequently, arrayindex(..., 0) extracts the first element (the first octet) as a string.
Output:
101
192.168.1.10
["192", "168", "1", "10"]
192
102
10.0.0.5
["10", "0", "0", "5"]
10
Related articles
Functions:
arrayindex,to_string,arraystring
Last updated
Was this helpful?
