Skip to content
SPL // Splunk

Using the erex Command

KGI Avatar

Written by: Ellis DeVaney | Last Updated:

March 27, 2024
splunk erex image

Originally Published:

March 27, 2024

Splunk, a powerful data analytics platform, enables users to collect, index, and analyze machine data from various sources. The Search Processing Language (SPL) lies at Splunk’s heart, allowing users to
search, filter, and manipulate data easily. The erex command provides powerful data extraction, especially when users face unfamiliar regex syntax or complex data patterns. In this blog post, we will explore the erex command and demonstrate its effectiveness in real-world scenarios.

When to Utilize the erex Command

The erex command in Splunk is designed to simplify the process of data extraction when users lack knowledge of the regular expressions required. Instead of struggling with complex syntax, users can provide example values to instruct Splunk to automatically generate regular expressions to extract similar patterns from the data. Essentially, this command streamlines the data extraction process allowing users to focus on data insights rather than grappling with complex regular expression syntax. It should be noted that the regex produced by erex is often less performant regex for the desired extraction, but can be used as a great starting point in the extraction process.


After executing a successful erex command, users can access a more efficient rex command from the Job dropdown under the SPL box in Splunk. This produces a rex command that will be more performant while still providing the necessary data.


Proper Command Syntax

The syntax for erex usage is as follows:

					erex [<field>] examples=<string> [<counterexamples=<string>] [<fromfield=<field>] [<maxtrainers=<integer>]
  • field: Specifies the name of the new field to store the extracted values
  • examples: A comma-separated list of example values representing the information to extract
  • counterexamples (optional): A list of example values that should not be extracted
  • fromfield (optional): Specifies the existing field from which to extract information
  • maxtrainers (optional): Sets the maximum number of values to learn from (default is 100)

Benefits of Usage

  • Automatic Regular Expression Generation: The erex command automatically generates regular expressions based on example values provided by users, eliminating the need for manual crafting of regular expressions.
  • Simplified Data Extraction: Users can quickly extract structured data from unstructured sources by leveraging the erex command’s ability to generate regular expressions tailored to their specific data patterns.
  • Enhanced Productivity: By automating the regular expression generation process, the erex command accelerates data extraction tasks, enabling users to derive insights from their data more efficiently.

Sample Use Cases

Example 1: Extracting Email Addresses from Web Logs

Use Case: Extract email addresses from web logs for analysis or investigative purposes.

Description: In this example, we will use the erex command to extract email addresses from web logs. It uses the erex command with examples to extract email addresses matching the provided patterns.

					sourcetype="web_logs" | erex email_address examples=",,"
Example 2: Extracting Ports from Security Logs

Use Case: Analyze poorly parsed security logs for specific activity on network ports.

Description: In this example, we search the “security_logs” sourcetype for port numbers using erex with provided examples. It then counts the occurrences of failed status for each port using the stats command.

					sourcetype="security_logs" | erex port examples="port 22, port 443, port 5534, port 4342, port 2112"
| stats count(eval(status=failed)) by port


In conclusion, Splunk’s erex command simplifies data extraction by automatically generating regular expressions based on user-provided examples. By leveraging erex, users can streamline data analysis workflows, boost productivity, and efficiently derive actionable insights from datasets. To summarize:

  • erex generates regular expressions automatically, based on example values provided by users.
  • The command enhances productivity and streamlines data analysis workflows.
  • It enables data professionals to extract valuable information from complex datasets efficiently.

Ultimately, the erex command remains an intuitive and powerful tool for anyone working with Splunk. Its ability to simplify the data extraction process makes it an indispensable asset for data professionals seeking to unlock valuable insights from their datasets.


To get access to more Splunk searches like the ones in this article, check out Atlas Search Library which is one of the elements in the Atlas Platform. Atlas Search Library is a curated list of optimized searches that you can use to empower your Splunk users to search without having to learn SPL. You can also create, customize and maintain your own library of searches to ensure that your users are getting the most from using Splunk.

Helpful? Don't forget to share this post!