Splunk Search

extract content of brackets

indeed_2000
Motivator

how can i extract content of first bracket if it is string?

e.g:
2020-04-21 23:59:59,093 INFO xxx.xxx-zz-00000 [process] start[ppp] time[00] tag[xxx]
2020-04-21 23:59:59,093 INFO xxx.xxx-zz-00000 [1234567] start[ppp] time[00] tag[xxx]
....

expected result:
process

have huge log file need to extract process with this conditions
1-content of first bracket
2-it must be string not number!

Thanks,

0 Karma

javiergn
Super Champion

Hi @mehrdad_2000,

If you just want whatever is between square brackets but ensuring it only contains letters and not numbers, you can do something like:

| rex max_match=1 "^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\,\d{3} \w+ [\w\-\.]+ \[(?<myField>[a-zA-Z]+)\]"

For instance, if I use your sample data:

alt text

0 Karma

indeed_2000
Motivator

As I mentioned this is large log file and need more complete regex to do this.
For example your answer extract only fixed pattern that i mention, but not work on these:

2020-04-21 23:59:59,093 INFO xxxx.xxxxx-zz-00000xxx111 [process] start[ppp] time[00] tag[xxx]
2020-04-21 23:59:59,093 INFO xx.xxx-zz-00000x [report] start[ppp] time[00] tag[xxx]

Expected output:
process
report

0 Karma

javiergn
Super Champion

Hmm, that's interesting. I have tested both your samples on regex101 and my regex works fine with them. Look:

https://regex101.com/r/cjjSHZ/1

0 Karma
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 ...

Shape the Future of Splunk: Join the Product Research Lab!

Join the Splunk Product Research Lab and connect with us in the Slack channel #product-research-lab to get ...

Auto-Injector for Everything Else: Making OpenTelemetry Truly Universal

You might have seen Splunk’s recent announcement about donating the OpenTelemetry Injector to the ...