Splunk Search

Help with rex- Unbalanced quotes when there are \ and " in string

jhcbazinga95
Loves-to-Learn Everything

Hey community,

Can someone help me out with a rex related question! Many many thanks!

I am trying to rex the V1 out of a sample string and I have tried  catalogVersion\\":\\"(?P<catalogVersion>[^ ]+)\\",  

In regex101, it is working, However, I am getting a Unbalanced quotes error in Splunk.

sample string

\"transferDisconnectReasons\":null,\"catalogVersion\":\"V1\",\"accountCustomerDetails\"

jhcbazinga95_0-1666906665894.png

 

jhcbazinga95_1-1666906692423.png

 

Cheers!

Labels (1)
0 Karma

jotne
Builder

In Splunk regex, if escaping does not work, add more \ until id does work 😉

 

johnhuang
Motivator

Yea, this is a pain.

1. You can double escape each backslash and escape each quotes.  You'll end up with something like this:

| rex field=_raw "catalogVersion\\\\\":\\\\\"(?P<catalogVersion>[^ ]+)\\\\\","


2. Or you can replace all the backslash in the data which makes it easier to parse:

| rex field=_raw mode=sed "s/\\\//g"
| rex field=_raw "catalogVersion\":\"(?P<catalogVersion>[^\"]*)"

 

3. Or you can substitute value of \ and " with its unicode hex equivalent

| rex field=_raw "catalogVersion\x5c\x22:\x5c\x22(?P<catalogVersion>[^ ]+)\x5c\x22,"

 

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...

Index This | How many sevens are there between 1 and 100?

August 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...