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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...