Splunk Search

rex extract literal stings with special characters

spicy
Path Finder

I have a list of hundreds of string values that need to be extracted from a field

the problem is the values that need to be extracted contain special characters i.e. (\, $, \\, ^, . . .)

Is there an easy way im missing to extract the literal characters?

what I have tried 
(example list)

| makeresults
| eval raw_field_example = "$money$ "?question?" "help$.." "random" "text"
| makemv raw_field_example delim=" "
| rex field=raw_field_example "(?<literal_items_I_want>"money"|$money$|"text"|"help$..")"

results for literal_items_I_want are only:
money 
text

tried putting the @ symbol before each double quotes but didnt work...


thanks for the help


Labels (1)
0 Karma
1 Solution

spicy
Path Finder

Ok I fount the answer...

\Qextract$anythin\gbetween\E|\Qsomethingelse\E

start with a \Q end with \E

and if your extracting a string that contains \E OR \Q you can rex mode=sed replace it to be \e \q prior to extraction, with case sensitivity turned off. 

View solution in original post

0 Karma

spicy
Path Finder

Ok I fount the answer...

\Qextract$anythin\gbetween\E|\Qsomethingelse\E

start with a \Q end with \E

and if your extracting a string that contains \E OR \Q you can rex mode=sed replace it to be \e \q prior to extraction, with case sensitivity turned off. 

0 Karma

manjunathmeti
Champion

hi @spicy,

You can escape special characters using back slash \. You can try this:

| makeresults
| eval raw_field_example = "$money$ question? help$.. random text"
| makemv raw_field_example delim=" " 
| rex field=raw_field_example max_match=0 "(?<literal_items_I_want>\W?\w+\W?)"

 

If this reply helps you, a like would be appreciated.

0 Karma

spicy
Path Finder

The _raw field will be a lot more randomness. The list of strings I am searching is quite complex as well, would not be able to add \ to every string for extraction.

0 Karma

venkatasri
SplunkTrust
SplunkTrust

Hi @spicy  how is your _raw events looks like can you paste here and what's your requirement which content to be extracted?

 

--

An upvote would be appreciated if this reply helps!

0 Karma

spicy
Path Finder

The _raw is mostly network logs. netflow, all zeek types, 0365, web, and some EDR solutions with enrichment

so its kind of all over the place. 

all formats too, json, csv, tab delimited.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...