Splunk Search

How to write a Regex to search globally?

onthakur
Engager

below is the data which has multiple features for a single item. I want to write a regex which could search all occurrences of feature (not just first occurance) and then count the feature . I have written below search string but count value is not consistent. can someone plz take a look and advice.

Many thanks in advance.

|makeresults
| eval _raw="[{\"\"feature\"\": \"\"INTDATA\"\"},
{\"\"feature\"\": \"\"INTDATA2\"\"},
{\"\"feature\"\": \"\"MGDAT0\"\"},
{\"\"feature\"\": \"\"MGPR2TI\"\"},
{\"\"feature\"\": \"\"MSTORE\"\"},
{\"\"feature\"\": \"\"PNINCLWAP\"\"},
{\"\"feature\"\": \"\"PRMCAFIND\"\"},
{\"\"feature\"\": \"\"3WY\"\"},
{\"\"feature\"\": \"\"CFC\"\"},
{\"\"feature\"\": \"\"CFU\"\"},
{\"\"feature\"\": \"\"CLIP\"\"},
{\"\"feature\"\": \"\"CLIR\"\"},
{\"\"feature\"\": \"\"CLW\"\"},
{\"\"feature\"\": \"\"DATA\"\"},
{\"\"feature\"\": \"\"CAMTAC\"\"},
{\"\"feature\"\": \"\"HOLD\"\"},
{\"\"feature\"\": \"\"INROAM\"\"},
{\"\"feature\"\": \"\"ISP\"\"},
{\"\"feature\"\": \"\"MSTORE\"\"},
{\"\"feature\"\": \"\"NWROAM\"\"},
{\"\"feature\"\": \"\"PERMGL\"\"},
{\"\"feature\"\": \"\"SMSO\"\"},
{\"\"feature\"\": \"\"VM\"\"},
{\"\"feature\"\": \"\"GFLEX\"\"}]"
|rex max_match=0 "\"\"feature\"\": \"\"(?<feature>.*?)\"\"}"
|stats count(feature) by feature

Labels (3)
0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try like this

|makeresults
| eval _raw="[{\"\"feature\"\": \"\"INTDATA\"\"},
{\"\"feature\"\": \"\"INTDATA2\"\"},
{\"\"feature\"\": \"\"MGDAT0\"\"},
{\"\"feature\"\": \"\"MGPR2TI\"\"},
{\"\"feature\"\": \"\"MSTORE\"\"},
{\"\"feature\"\": \"\"PNINCLWAP\"\"},
{\"\"feature\"\": \"\"PRMCAFIND\"\"},
{\"\"feature\"\": \"\"3WY\"\"},
{\"\"feature\"\": \"\"CFC\"\"},
{\"\"feature\"\": \"\"CFU\"\"},
{\"\"feature\"\": \"\"CLIP\"\"},
{\"\"feature\"\": \"\"CLIR\"\"},
{\"\"feature\"\": \"\"CLW\"\"},
{\"\"feature\"\": \"\"DATA\"\"},
{\"\"feature\"\": \"\"CAMTAC\"\"},
{\"\"feature\"\": \"\"HOLD\"\"},
{\"\"feature\"\": \"\"INROAM\"\"},
{\"\"feature\"\": \"\"ISP\"\"},
{\"\"feature\"\": \"\"MSTORE\"\"},
{\"\"feature\"\": \"\"NWROAM\"\"},
{\"\"feature\"\": \"\"PERMGL\"\"},
{\"\"feature\"\": \"\"SMSO\"\"},
{\"\"feature\"\": \"\"VM\"\"},
{\"\"feature\"\": \"\"GFLEX\"\"}]"
|rex max_match=0 "\"\"feature\"\": \"\"(?<feature>.*?)\"\"}"| mvexpand feature
|stats count(feature) by feature
0 Karma

onthakur
Engager

thank you that works.

0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud | Unified Identity - Now Available for Existing Splunk ...

Raise your hand if you’ve already forgotten your username or password when logging into an account. (We can’t ...

Index This | How many sides does a circle have?

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

Registration for Splunk University is Now Open!

Are you ready for an adventure in learning?   Brace yourselves because Splunk University is back, and it's ...