Splunk Search

Why am I unable to extract this field with my current rex statement?

jmaple
Communicator

I have a regex that should be extracting the employeeType field from an event. Below is the text of the event and the regex I am using.

Details:  
    Attributes:
        employeeType
            Contractor

Search:

mysearch | rex "employeeType\n\t\t\t(?<employeeType>\w+)"

We see the extraction work on regxr, but it doesn't seem to extract in the search.

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Try ... | rex "employeeType\s*(?<employeeType>\w+)".

---
If this reply helps you, Karma would be appreciated.

View solution in original post

jbailey_splunk
Splunk Employee
Splunk Employee

Are you sure there are tabs preceding the "employeeType" value? Here's a few suggestions to try:

employeeType\n\t+(?\w+)

If there are tabs prior to the employeeType value, this should account for 1 or more tabs in the regex

employeeType\n\s+(?\w+)

If these are actually spaces, this should work

employeeType\s+(?\w+)

In my quick testing on https://regex101.com, I observed the regex did not need the newline token (\n) - so you could try your regex without it

Hope this helps,
Jamie

0 Karma

jmaple
Communicator

The raw value did not have the newline like the event appears to in the search which is why it worked in my testing because I was using the formatting presented with the search. In any case, richgalloway solved my issue. Thanks for replying!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try ... | rex "employeeType\s*(?<employeeType>\w+)".

---
If this reply helps you, Karma would be appreciated.

jmaple
Communicator

Well now don't I feel silly... Thanks.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...