Splunk Search

Why am I unable to extract a field from my logs with rex using my current regular expression?

mitcanmit
Explorer

In my logs, I have the below part and I want to extract success

{\"state\":\"success\",

How do I formulate it with rex? I know that I should escape the backslashes and quotes but adding a \ does not do the trick. This is what I have tried:

| rex "\\\"state\\\":\\\"(?<state>\w*)\\\""
0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try as well

your base search | rex   "(\\\)*\"state(\\\)*\":(\\\)*\"(?<state>\w*)(\\\)*\""

View solution in original post

somesoni2
Revered Legend

Give this a try as well

your base search | rex   "(\\\)*\"state(\\\)*\":(\\\)*\"(?<state>\w*)(\\\)*\""

richgalloway
SplunkTrust
SplunkTrust

Your regex string worked perfectly on regex101.com, but sometimes Splunk gets confused by quotation marks within strings. Try this alternative:

"\\\x22state\\\x22:\\\x22(?<state>\w*)\\\x22"
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

Get Inspired! We’ve Got Validation that Your Hard Work is Paying Off

We love our Splunk Community and want you to feel inspired by all your hard work! Eric Fusilero, our VP of ...

What's New in Splunk Enterprise 9.4: Features to Power Your Digital Resilience

Hey Splunky People! We are excited to share the latest updates in Splunk Enterprise 9.4. In this release we ...