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
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...