Splunk Search

Need help with regular expression/rex

jameskerivan
Explorer

Hi,

Sorry I am having a tough time with this regular expression. I have a field named transaction_type and there are values in the field I want to extract. The field looks like this fieldA||fieldB||fieldC||fieldD. Now I want to be able to look at each individual field. I am having a tough time understanding how regular expressions work.

basic query | rex field=transaction_type "(?FieldB.*)||(?FieldC.*)" | table transaction_type FieldB

So I want my delimiter to be ||. I have tried multiple combinations and nothing is coming out as I expect it to.

Thank you for your help!

0 Karma
1 Solution

Richfez
SplunkTrust
SplunkTrust

(Edits: sorry, editor kept eating my fields)

One problem is escaping. The pipes | need to be escaped with a preceding \ character.

... | rex field=transaction_type "(?<f1>.*)\|\|(?<f2>.*)\|\|(?<f3>.*)\|\|(?<f4>.*)"

That takes an existing field that is already called "transaction_type" and looks like this: fieldA||fieldB||fieldC||fieldD and splits it into 4 parts named f1, f2, f3 and f4. There are quite a few ways to skin this particular cat, but that is probably the simplest regex way.

I'd suggest spending some time at a regex tutorial site, like perhaps here.
Here's a fun site to play with once you've done a bit of the tutorial.

View solution in original post

Richfez
SplunkTrust
SplunkTrust

(Edits: sorry, editor kept eating my fields)

One problem is escaping. The pipes | need to be escaped with a preceding \ character.

... | rex field=transaction_type "(?<f1>.*)\|\|(?<f2>.*)\|\|(?<f3>.*)\|\|(?<f4>.*)"

That takes an existing field that is already called "transaction_type" and looks like this: fieldA||fieldB||fieldC||fieldD and splits it into 4 parts named f1, f2, f3 and f4. There are quite a few ways to skin this particular cat, but that is probably the simplest regex way.

I'd suggest spending some time at a regex tutorial site, like perhaps here.
Here's a fun site to play with once you've done a bit of the tutorial.

jameskerivan
Explorer

Thank you! I appreciate it.

0 Karma
Get Updates on the Splunk Community!

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

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...