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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...