Splunk Search

Excluding multiple slashes throughout regex capture string

splunkrush
Engager

Trying to figure out how to extract a field using regex to capture the entire string.  Only problem is there are a bunch of slashes throughout.  Sometimes one, sometimes 3, etc.  I've tried variations of commands I found in the documentation but no luck.  is this possible?

Example String of Field I want to extract with all the context appended to one another minus the slashes:

\"\\\"Field1\\\":\"context"\\\",\\\:"\"context"\\\",\\\:"\"context"\\\",\\\:"\"context"\\\",\\\:"\"context"\\\"context\\\\\\\context\\\\\\\\Field2

Want it to be extracted like this: Field1="context","context" etc so slashes are eliminated.  Appreciate any help.

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You can simply remove the backslashes like this

| rex field=_raw mode=sed "s/\\\//g"

However, I suspect this is not what you want, but what you want it unclear since all your data is "context". Are you expecting Field1 to be "context,context,context", or something else?

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

You can simply remove the backslashes like this

| rex field=_raw mode=sed "s/\\\//g"

However, I suspect this is not what you want, but what you want it unclear since all your data is "context". Are you expecting Field1 to be "context,context,context", or something else?

splunkrush
Engager

Thank you, that did the trick.  I was trying to do everything through the field extraction page, but using 'sed' worked better.  It kept all the context I needed and eliminated all the slashes.

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

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

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...