Splunk Search

How to edit my regular expression to extract fields that contain "CASE" but not "Case" or "case"?

kiran_mh
Explorer

Hi,

I have the following expression (?=[^C]*(?:CASE|C.*CASE))^(?:[^:\n]*:){5}\s+\w+(?P.+), which is used to extract fields but I only want fields that contain "CASE" and not "Case" or "case".

Thank you

Regards,
KIran

0 Karma

sundareshr
Legend

If you want to only retrieve events with CASE, use the CASE() function in your base search

index=foo CASE("CASE") | ...
0 Karma

gokadroid
Motivator

Assuming you are interested in strings which start with CASE and need to be stored in field1 then you can use following rex. It will work on strings starting with CASE, example CASE abc: 22 and save everything upto a : or a new line \n like CASE abc in field1

your query to return events
| rex field=_raw "(?<field1>(CASE)[^:\n]+)"
| complete your query using field1

If you can post some specific sample logs of what you want to extract then this regex can be refined.

0 Karma

gokadroid
Motivator

to get the logs which only contain CASE try this:

index=yourIndex sourcetype=yourSourcetype (CASE)

0 Karma

kiran_mh
Explorer

Thank you gokaroid,

We need only the logs that contain "CASE"- all upper case, rest like "Case" should be discarded

Please help with this..

Thanks in advance

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

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