Splunk Search

Getting data out of an event with a regular expression

MattPainting
New Member

I am trying to figure out how to get data out of the event and into a field. I need to get all the data in brackets.

Sample data:

Run,jump,fly[walk]dog/cat

File storage ,[app - run] development

I want the result put into a new field and look like this:

walk

app - run

Labels (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @MattPainting,

if you want to extarct a field from a log, I hint to use the guided self extractor.

Anyway, using a regex, you can extract the value between square parenthesis putting it into a field:

| rex "\[(?<my_field>[^\]]+)"

Ciao.

Giuseppe

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "\[(?<result>[^\]]+)"

use max_match=0 if there is more than one bracketed result in an event

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...