Splunk Search

Rex to Exclude + Sign

IRHM73
Motivator

I wonder whether someone may be able to help me please.

I'm trying to extract the text "Comapred to previous years almost a pleasure to use" from the raw data as shown below

feedback-comments=Compared+to+previous+years+almost+a+pleasure+to+use&isJavascript

I've tried the following regex, which does extract the text but this includes the '+' sign.

feedback-comments=(?<comments>[^[]+)\&isJavascript

Could someone possibly tell me please how I would be able to write this so the '+' signs are excluded.

Many thanks and kind regards

Chris

0 Karma
1 Solution

gcato
Contributor

You can use the rex command in sed mode. Here's a run anywhere example

|stats c as feedback-comments |eval feedback-comments="Compared+to+previous+years+almost+a+pleasure+to+use&isJavascript"
| rex field="feedback-comments" "(?<comments>[^&]+)" |rex mode=sed field="comments" "s/\+/ /g"

Hope this helps.

View solution in original post

gcato
Contributor

You can use the rex command in sed mode. Here's a run anywhere example

|stats c as feedback-comments |eval feedback-comments="Compared+to+previous+years+almost+a+pleasure+to+use&isJavascript"
| rex field="feedback-comments" "(?<comments>[^&]+)" |rex mode=sed field="comments" "s/\+/ /g"

Hope this helps.

IRHM73
Motivator

Hi @gcato thank you for this, but unfortunately this doesn't extract any of the information.

Kind Regards

Chris

0 Karma

richgalloway
SplunkTrust
SplunkTrust

@gcato's answer works for me. You only need the rex commands in your search. If it's not doing what you expect then please clarify your needs. For instance, to eliminate plus signs instead of replacing them with spaces use rex mode=sed field="comments" "s/\+//g".

---
If this reply helps you, Karma would be appreciated.
0 Karma

IRHM73
Motivator

Ah that was it, thank you for coming back to me with this.

Kind Regards

Chris

0 Karma

richgalloway
SplunkTrust
SplunkTrust

If your problem is solved, please accept the answer.

---
If this reply helps you, Karma would be appreciated.
0 Karma

chrisprodger
New Member

Hi gcato, if you would like to change your comment to an answer I can accept this for you.

Many thanks and kind regards

Chris

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!

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 ...

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 ...