Splunk Search

Help with regex - How to exclude multiple parentheses and slashes from a field?

jalo23
Explorer

Is there a more elegant way to do this? New to using rex & I can’t seem to strip out the multiple parentheses and slashes from a field without using replace.  (I don't have control over the data, I know it is better to strip it out first.) These do work but in some cases there are more parentheses and slashes - is there a way to strip all of them out at once, or do I need to make repeating phrases?

| rex mode=sed field=Field_A "s/\(\)/ /g"

| rex mode=sed field=Field_B "s/\(\)/ /g"

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

Labels (3)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

You can combine the parentheses and slash into a character class to strip them all out at once.  You will, however, need a separate rex command for each field being processed.

| rex mode=sed field=Field_A "s;[\(\)/];;g"

| rex mode=sed field=Field_B "s;[\(\)/];;g"
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

You can combine the parentheses and slash into a character class to strip them all out at once.  You will, however, need a separate rex command for each field being processed.

| rex mode=sed field=Field_A "s;[\(\)/];;g"

| rex mode=sed field=Field_B "s;[\(\)/];;g"
---
If this reply helps you, Karma would be appreciated.

jalo23
Explorer

That worked great, thank you!

| rex mode=sed field=Field_A "s;[\(\)/];;g"
| rex mode=sed field=Field_A "s;[\(\)/];;g"
| rex mode=sed field=Field_A "s/\(\)/ /g"
| rex mode=sed field=Field_A "s/\// /g"
| rex mode=sed field=Field_A "s/\// /g"

0 Karma
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!

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...