Splunk Search

Extract the User-Agent from HTTP request

ashishmgupta
Explorer

Below the excerpt from my HTTP request and I'm trying to get the User-Agent value from it and so far not successful. Will appreciate any help.

This Splunk editor is removing the carriage return and line feed characters so below is the regex101 link.https://regex101.com/r/rdu8yE/1

Also attached is the screenshot of the HTTP request.

 

 

Labels (2)
0 Karma
1 Solution

ashishmgupta
Explorer

looks like 4 backslashes to get two? Below worked. Thank you for your help. 

User-Agent: (?<UserAgent>[^\\\\]*)

View solution in original post

0 Karma

ashishmgupta
Explorer

looks like 4 backslashes to get two? Below worked. Thank you for your help. 

User-Agent: (?<UserAgent>[^\\\\]*)

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Your regex was very close.  This worked for me using the one example:

User-Agent: (?<UserAgent>[^\\]*)
---
If this reply helps you, Karma would be appreciated.

ashishmgupta
Explorer

Error in 'rex' command: Encountered the following error while compiling the regex 'User-Agent: (?<UserAgent>[^\]*)': Regex: missing terminating ] for character class.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

To use backslashes in a regex in SPL you have to escape them.

User-Agent: (?<UserAgent>[^\\\\\\]*)

Yes, that's 6 backslashes to get two.

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...