Splunk Search

Remove the query string from a Url field

gassershaun
Engager

Need to exclude the query parameters from a URL field.
For e.g. the field contains http://www.google.com/india?search=splunk. I need to substring this such that result field only contains http://www.google.com/india i.e. remove the part following "?" character. Tried using the eval and the replace functions but did not work...

Tags (1)
0 Karma

zsteinkamp_splu
Splunk Employee
Splunk Employee

Ayn's answer fails if the URL does not include a question mark. Here is a regex that works for URLs with and without a question mark:

| rex field=your_url_field "^(?<your_new_url_field>[^?]+)

Ayn
Legend
... | rex field=your_url_field "^(?<your_new_url_field>.+?)\?"

Ayn
Legend

Ah. Updated my answer with a corrected regex.

gassershaun
Engager

Thanks it works.. however one small problem I get the result as http://www.google.com/india? and not as http://www.google.com/india I also need to get rid of the ending ?

0 Karma
Get Updates on the Splunk Community!

Splunk Platform | Upgrading your Splunk Deployment to Python 3.9

Splunk initially announced the removal of Python 2 during the release of Splunk Enterprise 8.0.0, aiming to ...

From Product Design to User Insights: Boosting App Developer Identity on Splunkbase

co-authored by Yiyun Zhu & Dan Hosaka Engaging with the Community at .conf24 At .conf24, we revitalized the ...

Detect and Resolve Issues in a Kubernetes Environment

We’ve gone through common problems one can encounter in a Kubernetes environment, their impacts, and the ...