Splunk Search

Manually modifying regex for a field extraction. It is grabbing the wrong data.

KindaWorking
Path Finder

I am quite new to both Regex and Splunk. When doing a field extraction for an image, I did not like the results, so I started modifying the regular expression myself. Instead of grabbing the data I want, it is just selecting the white space directly after the data I want. for instance I am using this for my field extraction:

image\=([\w]+)(?)

I am wanting it to grab the data after "image="

And here is an example of some of the data I am looking at:

0.0.0.0 - - [12/Dec/2014:07:43:56 +1100] "GET /pdf.cfm?handle=pra&image=ImageName%20&src=Direct HTTP/1.1" 302 69 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"  

It is just highlighting what looks like a space that does not exist inbetween the ImageName and the '%'

Can someone please let me know where I went wrong with my expression?

0 Karma
1 Solution

vasanthmss
Motivator

Hi,

Try this rex,

| rex field=_raw "image=(?<field1>.*)&"  

to extract the "image" field and use urldecode() function to remove the url decode chars.

Sample search:

|stats count| eval _raw=" 0.0.0.0 - - [12/Dec/2014:07:43:56 +1100] \"GET /pdf.cfm?handle=pra&image=ImageName%20&src=Direct HTTP/1.1\" 302 69 \"-\" \"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)\"" | rex field=_raw "image=(?<field1>.*)&" | eval field1= urldecode(field1)

Cheeerrrsss!

V

View solution in original post

KindaWorking
Path Finder

Oops sorry, done now. Thanks again

0 Karma

KindaWorking
Path Finder

Perfect! Thank you so much vasanthmss!

0 Karma

vasanthmss
Motivator

If its useful please accept the answer. Cheers!

V
0 Karma

vasanthmss
Motivator

Hi,

Try this rex,

| rex field=_raw "image=(?<field1>.*)&"  

to extract the "image" field and use urldecode() function to remove the url decode chars.

Sample search:

|stats count| eval _raw=" 0.0.0.0 - - [12/Dec/2014:07:43:56 +1100] \"GET /pdf.cfm?handle=pra&image=ImageName%20&src=Direct HTTP/1.1\" 302 69 \"-\" \"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)\"" | rex field=_raw "image=(?<field1>.*)&" | eval field1= urldecode(field1)

Cheeerrrsss!

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