Splunk Search

How to drop brackets from field extraction result?

vcorral
New Member

I have some logs that are very inconsistent and need to get a source number that is displayed one of few different ways:

  Source Number: 47107
  Source id: Meter <47107>
  Source id: 47107

I can successfully weed out all of the Source prefixes, but I can't find a way to remove the "<" and ">" from the field extraction. Here is what I have tried so far:

(?:Source\sid:|Source\sNumber:)(?:\sMeter\s|\s)(?<MeterNumber>((?:<)\d*(?:>)|\d*))

We can see that I tried ignoring the "<" and ">", but they are still showing up in search results.

Is there any way I can drop them as part of the field extraction?
Thanks in advance!
Virgil

0 Karma

evania
Splunk Employee
Splunk Employee

Hi @vcorral ,

Did you have a chance to check out these answers yet? If any of them worked, please resolve this post by approving it! If your problem is still not solved, keep us updated so that someone else can help you.

Thanks for posting!

0 Karma

vcorral
New Member

Thank you all for your quick and informative responses. I was too far into the issue and could not see the forest through the trees. I did move the "<" outside of the named capture group and added it to the one string that utilized it in the preceding non-capture group.

I also changed the "\d*" to "\d+", thanks for keeping me straight on that.

My new REGEX is as follows:

(?:Source\sid:|Source\sNumber:)(?:\sMeter\s<|\s)(?<MeterNumber>(\d+))
0 Karma

anthonymelita
Contributor

In Splunk because you only really care about the named extracted field, you don't need to worry about the non-capture groups. Just move the bracket outside the extraction:

(Source\sid:|Source\sNumber:)(\sMeter\s|\s)(<*)(?\d+)

I had to change the d(star) to d+ because it's interpreting as italics

0 Karma

MuS
SplunkTrust
SplunkTrust

Hi vcorral,

Please give this regex a try:

 Source (?:Number|id):[\s\w\<]+?(?<myNumber>\d+)

cheers, MuS

0 Karma
Get Updates on the Splunk Community!

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

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

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...