Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

regexcapture

Use the regexcapture() function to extract from a string substrings that match specified named regular expression groups and return them as a JSON object.

Syntax

regexcapture (<field>, "<pattern>")

Parameters

Name
Type
Required
Description

field

string

Yes

The string field (typically _raw_log) or literal to apply the regex to.

pattern

string

Yes

The regular expression string, enclosed in double quotes, containing named capture groups ((?P<name>...)).

Returns

The regexcapture() function returns a JSON object where the keys correspond to the named capture groups defined in the regex pattern, and the values are the extracted substrings.

Usage notes

  • The regexcapture() function is only supported in the XQL syntax for parsing rules. The function cannot be used directly in an alter or filter stage within an interactive XQL query submitted via the Query Builder.

  • XQL utilizes the RE2 regular expression implementation.

  • For case-insensitive matching, you can include (?i) at the beginning of your regular expression pattern. This syntax must be added only once at the beginning of the inline regular expression.

  • Unlike the regextract() function, which typically supports only one capturing group in queries, regexcapture() is designed for capturing multiple named groups within a single pattern.

  • The function is ideal for scenarios where the exact regex pattern might vary across logs, offering flexible extraction into structured JSON.

Examples

Example 1: Extracting user and IP address from a login log

Goal: Extract the username and source IP address from a raw log using named capture groups.

XQL code:

Explanation: A conceptual Parsing Rule would apply the regex pattern to the raw log. The named groups username and source_ip would capture "Alice" and "192.168.1.10" respectively, forming the JSON object {"username": "Alice", "source_ip": "192.168.1.10"} in the extracted_info field.

Output:

EVENT_ID
LOG_ENTRY
EXTRACTED_INFO

101

"User Alice logged in from 192.168.1.10"

{"username": "Alice", "source_ip": "192.168.1.10"}

Example 2: Extracting process name and file path from an access log

Goal: Extract a process name and a file path from a system log entry.

XQL code:

Explanation: The conceptual Parsing Rule extracts "cmd.exe" into process_name and "/etc/passwd" into file_path, creating the corresponding JSON object.

Output:

EVENT_ID
LOG_ENTRY
EXTRACTED_INFO

102

"Process cmd.exe attempted to access /etc/passwd"

{"process_name": "cmd.exe", "file_path": "/etc/passwd"}

Example 3: Extracting destination IP address, port, and application ID (with case-insensitive matching)

Goal: Extract network details and an application ID from a network connection log using case-insensitive matching.

XQL code:

Explanation: The conceptual Parsing Rule uses (?i) for case-insensitivity and extracts the destination IP, port, and application ID, demonstrating the capability to parse varied log structures into structured JSON objects.

Output:

EVENT_ID
LOG_ENTRY
EXTRACTED_INFO

103

"Outbound connection to 1.1.1.1:443 initiated by AppX"

{"dest_ip": "1.1.1.1", "port": "443", "app_id": "AppX"}

Last updated

Was this helpful?