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
Revered Legend

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
Motivator

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
Revered Legend

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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...