Splunk Search

Can someone please give me an explanation as to what the below rex command is doing?

auzark
Communicator

Can someone please give me an explanation as to what the below rex command is doing.

I do not understand the w+ s+ d+ etc........

| rex field=_raw "(?ms)^\\w+\\s+\\d+\\s+\\d+:\\d+:\\d+\\s+\\w+\\s+\\w+\\s+\\w+:\\s+\\w+:\\s+\\w+\\s+\\w+:\\s+\\w+\\s+\\w+\\s+\\w+:\\s+\\d+\\s+\\w+\\s+\\w+:\\s+\\d+\\-\\d+\\-\\d+\\s+\\d+:\\d+:\\d+\\s+\\w+:\\s+

 

(?P<Time>[^ ]+)\\s+

(?P<Trn_Total>\\d+)\\s+

(?P<Trn_Interval>\\d+)\\s+

(?P<TPS>[^ ]+)\\s+

(?P<SW_Inbound>[^ ]+)\\s+

(?P<SW_Outbound>[^ ]+)\\s+

(?P<SW_Total>[^ ]+)\\s+

(?P<SW_Ext_Pmc>[^ ]+)\\s+

(?P<SW_Int_Pmc>\\d+\\.\\d+)" offset_field=_extracted_fields_bounds

Labels (1)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @auzark,

the best approach is to read the links that @bowesmana shared.

In few words, the objects in regexes are a way to represent the strings to read, in other words, if you have to read 

2022-12-08 21:25:03 10.10.10.10 user goofy successfully accessed host srvwin001 from 10.10.20.241

and you have to extract a part of the string (e.g. "goofy") you have to identi

2022-12-08 21:25:03 10.10.10.10 user goofy successfully accessed host srvwin001 from 10.10.20.241

fy the part of the string using the objects, from the beginning e.g.

^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+user\s+(?<user>\w+)

or from a fixed point

user\s+(?<user>\w+)

the group inside quotes "?<field_name>\w+" is the field to extract, all that is outside quotes is useful to identify the field to extract.

you can find the meaning of each objects in regex101.com.

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @auzark,

the best approach is to read the links that @bowesmana shared.

In few words, the objects in regexes are a way to represent the strings to read, in other words, if you have to read 

2022-12-08 21:25:03 10.10.10.10 user goofy successfully accessed host srvwin001 from 10.10.20.241

and you have to extract a part of the string (e.g. "goofy") you have to identi

2022-12-08 21:25:03 10.10.10.10 user goofy successfully accessed host srvwin001 from 10.10.20.241

fy the part of the string using the objects, from the beginning e.g.

^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+user\s+(?<user>\w+)

or from a fixed point

user\s+(?<user>\w+)

the group inside quotes "?<field_name>\w+" is the field to extract, all that is outside quotes is useful to identify the field to extract.

you can find the meaning of each objects in regex101.com.

Ciao.

Giuseppe

bowesmana
SplunkTrust
SplunkTrust

Good starting point for understanding regex is

https://regex101.com/

and

https://www.regular-expressions.info/

You can see documentation on the shorthand character classes, such as \d, \w and \s here

https://www.regular-expressions.info/shorthand.html

Brackets are using for capturing groups - e.g. (?P<Time>[^ ]+)

https://www.regular-expressions.info/brackets.html

captures the expression matched by all characters up to the subsequent space into the field called Time

Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...