Splunk Search

regular express to stop at "="

wuming79
Path Finder

Hi, I have a search string that does the following:

temperature sourcetype=kaa | rex field=_raw "\"endpointKeyHash\":{\"string\":\"(?[^\"])\".\"Event\": (?{.*})$" | spath input=mydata | table _time, temperature, endpoint

The results will have 3 columns as _time, endpoint, temperature.
Under endpoint, it will reflect something like MASHjkasdhfa=.

I wanted to extract just MASHjkasdhfa but I can't do it with (?[^=]*)? How should I phrase it?

Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi wuming79,
sorry, could you share an example of your logs?
in addition could you format as Code Sample you regex, because isn't readable.

Bye.
Giuseppe

View solution in original post

0 Karma

woodcock
Esteemed Legend

You are probably using .* to capture the field, switch this to [^=]* instead.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi wuming79,
sorry, could you share an example of your logs?
in addition could you format as Code Sample you regex, because isn't readable.

Bye.
Giuseppe

0 Karma

wuming79
Path Finder

Hi,

The log is in this format under _raw field. Sorry, how do I paste it as Code Sample?

2641328 [EPS-log-dispatcher-11] INFO 1.24978294676695149906 - {"Log Header": "{"endpointKeyHash":{"string":"MAz7MadOhr02tPt5vtZsSEy9FWw="},"applicationToken":{"string":"24978294676695149906"},"headerVersion":{"int":1},"timestamp":{"long":1495594584490},"logSchemaVersion":{"int":2}}","Event":{"temperature":-1,"timeStamp":1495594583638}}

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi wuming79,
if I correctly understand: you want to extract the string between double quotes after endpointKeyHash and String, correct?

if this is your need, your regex is

endpointKeyHash\":\{\"string\":\"(?<endpointKeyHash>[^\=\"]*)

you can test it at https://regex101.com/r/rbE3YH/1

When you insert a regex in a message, you have to select it and click on the "Code Sample" button (the one with 101010 numbers): in this way it's possible to see special characters.

Bye.
Giuseppe

0 Karma

wuming79
Path Finder

Thanks Giuseppe. I got it now.

0 Karma

harshal_chakran
Builder

Use following rex to extract text before "=" symbol

|rex field=endpoint "(?<extracted_endpoint>.+?)="

Try using regex101 for generating rex in future

0 Karma

wuming79
Path Finder

Not sure why my original question was not updated. I need to correct my search string which is

temperature sourcetype=kaa_file | rex field=_raw "\"endpointKeyHash\":{\"string\":\"(?[^\"])\".\"Event\": (?{.*})$" | spath input=mydata | table _time, temperature, endpoint

I tried replacing "(?[^\"]*) with "(?.+?)=" and it works. But what does .+?)= means? I thought everything that I wanted to extract should be within the ( )?

0 Karma

damiensurat
Contributor

Go to regex101.com and enter your string and the regex. It will tell you exactly what each of the different symbols are doing on the right hand side of the extraction. Cheers.

0 Karma
Get Updates on the Splunk Community!

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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

A Guide To Cloud Migration Success

As enterprises’ rapid expansion to the cloud continues, IT leaders are continuously looking for ways to focus ...

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...