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

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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...