Splunk Search

How to write a regular expression for my field?

sravankaripe
Communicator

i want to extract field by regular expression. how can i write regular expression for the below one?

"responseCode":"200"

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try this

your base search | rex "\"responseCode\":\"(?<response_code>\d+)"

Based on the same data, it seems your data may be json format and you can get the fields extracted automatically (or you can set that up). Is it a proper json?

View solution in original post

horsefez
SplunkTrust
SplunkTrust

Hi sravankaripe,

 | rex field=_raw "(?:.*responseCode\s?\:\s?)(?<response_code>\d+)"

Gives you a field with the name "response_code" with the specific value.

Let me know if it works and check out this great site
https://regex101.com

Regards,
pyro_wood

PS:.... god damn.... somesoni at it again, stealin my karma 😄

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try this

your base search | rex "\"responseCode\":\"(?<response_code>\d+)"

Based on the same data, it seems your data may be json format and you can get the fields extracted automatically (or you can set that up). Is it a proper json?

Get Updates on the Splunk Community!

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

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...