Splunk Search

extarct specific field with regex

khanlarloo
Explorer

i want to extract the field with the name of http_agent from my logs
the raw field is :

"http_host=""nts.mapnanyp.com""","http_agent=""Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0""",http_retcode=200,"msg=""HTTP get request from,content_switch_name="none",server_pool_name="NTS","user_name=""Unknown""","http_refer=""https://mysite/dashboard/new/datalist.aspx?

i want just show the result before http_retcode, the result should be

(http_agent=""Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0)

can you tell me how can i do that?

Tags (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@khanlarloo

try this:

YOUR_SEARCH  | rex field=_raw "\"(?<A>http_agent=.*)\"\"\",http_retcode"

Sample Search:

| makeresults | eval _raw="\"http_host=\"\"nts.mapnanyp.com\"\"\",\"http_agent=\"\"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0\"\"\",http_retcode=200,\"msg=\"\"HTTP get request from,content_switch_name=\"none\",server_pool_name=\"NTS\",\"user_name=\"\"Unknown\"\"\",\"http_refer=\"\"https://mysite/dashboard/new/datalist.aspx?" | rex field=_raw "\"(?<A>http_agent=.*)\"\"\",http_retcode"
0 Karma

khanlarloo
Explorer

it doesn't work.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

does it return blank or unexpected output?

0 Karma

ddrillic
Ultra Champion

Looks most cheerful to me ; -)

alt text

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Are you looking for round brackets ()?
Then just append it... 🙂

eval A="(".A.")";

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...