Splunk Search

How can I extract just a section of a field?

mark_groenveld
Path Finder

I have a key called message

Inside the value are several results but I need to only extract one result in the middle of the results.

Sample:
message:  template: 1234abcd, eeid: 5678efgh, consumerid: broker

My rex is below but returns the template value but also the results for eeid  and consumerid when I only need the template value of 1234abcd.

| rex field=message "template: (?<TemplateID>[^-]+)"

Labels (1)
0 Karma
1 Solution

dtburrows3
Builder

I think this regex will capture just the value for template.

\s+template:\s+([^,]+)


The character after the carrot inside the square brackets means match on a character not in this list.
And adding a "+" after is a quantifier for 1 or more times. 

So doing "template: (?<TemplateID>[^-]+)" is matching on all characters after 'template: ' up until a "-" (which I dont see one in the example. So replacing the "-" with a "," I think will extract the value as intended.

dtburrows3_0-1703012277428.png

 




View solution in original post

dtburrows3
Builder

I think this regex will capture just the value for template.

\s+template:\s+([^,]+)


The character after the carrot inside the square brackets means match on a character not in this list.
And adding a "+" after is a quantifier for 1 or more times. 

So doing "template: (?<TemplateID>[^-]+)" is matching on all characters after 'template: ' up until a "-" (which I dont see one in the example. So replacing the "-" with a "," I think will extract the value as intended.

dtburrows3_0-1703012277428.png

 




mark_groenveld
Path Finder

That worked.  Thanks dtburrows3!

0 Karma
Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...