Splunk Search

Regular Expression two words pattern

royimad
Builder

Hello Splunkers,

I have a log file as follow:
Time1 WARN a.b.c
Time2 ERROR 1.2.3
Time3 FATAL a.b.c
Time2 WARN a.b.c
Time4 WARN a.b.c

If i want to select all the fields after WARN , i can write a regular expression as:
(?i) WARN (?P[^ ]+)
This will select all the fields after WARN.

What do i need to change if i want to select with the same regular expression the fields after ERROR with the fields after WARN?

Thanks,

Tags (1)
0 Karma

kristian_kolb
Ultra Champion

a) Time1 WARN some message here
b) Time2 ERROR some other message
c) Time3 FATAL yet another message

Given the events above, the following will happen

regex                                       your_field
(?i)(?:WARN|ERROR|FATAL)(?<your_field>[^ ]+)            some, some, yet (respectively)
(?i)(?:WARN|ERROR|FATAL)(?<your_field>.+)               the remainder of the events (including spaces)
(?i)(?:WARN|ERROR)(?<your_field>[^ ]+)                  some, some, null(respectively)

/k

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...