Splunk Search

How do I extract a part of a field via reg ex?

alakhotia
Explorer

I have a field with data like this:

loggingObject.methodName="WXYX.MNOController.myMethodName".

loggingObject.methodName="DEF.GHI.TUVController.myMethodName2"

 

I want to extract just the myMethodName part.  If the dot before it is there, that is fine.

I tried using the reg ex field extractor, this is what it came up with:

^(?:[^\.\n]*\.){9}(?P<methodName>\w+)

But it seems like it's creating a name for the extracted field, "methodName".

I then tried to use it my query like this:

 

| regex methodName="^(?:[^\.\n]*\.){9}(?P<methodName>\w+)"

 

But it doesn't work.  There also isn't anything in that line that tells it to extract from the loggingObject.methodName field specifically.

How can I extract what I'm trying to extract?

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

As you discovered, the regex field extractor leaves a lot to be desired.  It's OK to start with, but any freshman can produce a better expression.

The regex command filters events.  It does not extract fields.

Try this command to extract the methodName field at search time.

| rex field=loggingObject.methodName "\.(?<methodName>\w*?$)"

 

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

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

As you discovered, the regex field extractor leaves a lot to be desired.  It's OK to start with, but any freshman can produce a better expression.

The regex command filters events.  It does not extract fields.

Try this command to extract the methodName field at search time.

| rex field=loggingObject.methodName "\.(?<methodName>\w*?$)"

 

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

alakhotia
Explorer

That works, thank you.

What is the significance of "field"?  What value does it contain?

When I try outputting it in a table, it is blank.

But the extracted value that I wanted, was contained in the "methodName" that's in the regular expression term.

I would have thought that "field" would have contained the extracted value.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The "field" option contains the name of the field the rex command will use as input.  See https://docs.splunk.com/Documentation/Splunk/9.0.1/SearchReference/Rex#Syntax

The location(s) of the extracted value(s) is/are specified in the regex itself as one or more named capture groups.

If your problem is resolved, then please click the "Accept as Solution" button to help future readers.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...