Splunk Search

How to extract text from raw data using rex?

9jamie
Explorer

I'm new to regex and having trouble extracting some text. My raw data is in the following format:

ID=[12839829389-8b7e89opf][2839128391DJ33838PR]

I need to extract the text between the first two brackets,12839829389-8b7e89opf, into a new field. 

 

So far what I have does not work: | rex field=_raw "ID=[(?<id>.*)]"


If anyone could help it would be greatly appreciated.

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Square brackets are special characters in regex so need to be escaped with backslashes

| rex field=_raw "ID=\[(?<id>.*)\]"

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Square brackets are special characters in regex so need to be escaped with backslashes

| rex field=_raw "ID=\[(?<id>.*)\]"
0 Karma

9jamie
Explorer

this returns everything after ID up until the final closing bracket. so i added the brackets containing the second part of the id as well. final solution:

rex field=_raw "ID=\[(?<id>.*\]\[.*\]"

thanks for the help 

0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud’s AI Assistant in Action Series: Analyzing and ...

This is the second post in our Splunk Observability Cloud’s AI Assistant in Action series, in which we look at ...

Elevate Your Organization with Splunk’s Next Platform Evolution

 Thursday, July 10, 2025  |  11AM PDT / 2PM EDT Whether you're managing complex deployments or looking to ...

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...