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!

Exporting Splunk Apps

Join us on Monday, October 21 at 11 am PT | 2 pm ET!With the app export functionality, app developers and ...

Cisco Use Cases, ITSI Best Practices, and More New Articles from Splunk Lantern

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Build Your First SPL2 App!

Watch the recording now!.Do you want to SPL™, too? SPL2, Splunk's next-generation data search and preparation ...