All Apps and Add-ons

Regular expression in Splunk

saradachelluboy
Explorer

Hi All,

I want to read the string from specific location 34 till it reaches | line

I tried wrote regex as (?<=^.{34})\w+\S\d executed in https://regex101.com/ for the provided String
INFO | 2016-07-11 00:03:00,380 | jmsListenerA-9 |

But when I tried to execute the same in splunk
rex thread=_raw "(?<=^.{34})\w+-\d"

I am getting error : Error in 'rex' command: The regex '(?<=^.{34})\w+-\d' does not extract anything. It should specify at least one named group. Format: (?...).

Could some one pls help

0 Karma
1 Solution

rakesh_498115
Motivator

Hi sarada,

Try something like this.

rex "(?<=38)(?<WORD>[^|]+)"

View solution in original post

0 Karma

premraj_vs
Path Finder

You can try this

index=XXX 
| rex field=_raw ".+\[(?P<FIELD1>.+)]\s+(?P<FIELD2>.+)\s+for\s+(?P<FIELD3>.+)\/(?P<FIELD4>.+)"

This worked for me

0 Karma

hardik_splunk
Splunk Employee
Splunk Employee

You need to add capturing group in the rex command. This will be the name of the field, which will have extracted value.

for ex
index=_internal | eval data= "INFO | 2016-07-11 00:03:00,380 | jmsListenerA-9 |" | table data | rex field=data "(?<=^.{34})(?.*)|" | table thread

0 Karma

rakesh_498115
Motivator

Hi sarada,

Try something like this.

rex "(?<=38)(?<WORD>[^|]+)"
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...