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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...