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.

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