Getting Data In

regular expression json

efaundez
Path Finder

good afternoon

   I'm trying to capture a particular field, but sometimes my events come several times, and declaring the regular expression only captures a value.

   Any suggestions?

\"(code_key)\"\s*:\s*\"?(?[\w\d:.-]*)\"?

{ "_id" : { [ { "network_id_key" : "99999999" } ], "avps_key" : [], "services_key" : [ { "enabled_key" : true, "avps_key" : [], "code_key" : "IM_Prepago" } ], "billing_info_key" : {}, "start_date_key" : { "$date" : "2015-01-29T03:50:28.000-0300" }, "realm_key" : null, "name_key" : {}, "end_date_key" : null }

{ "_id" : {[ { "network_id_key" : "99999999" } ], "services_key" : [ { "avps_key" : [], "enabled_key" : true, "code_key" : "IM_Prepago" }, { "avps_key" : null, "enabled_key" : true, "code_key" : "TDE_IM_PP" }, { "code_key" : "TDE_ROAM_DEF", "avps_key" : null, "enabled_key" : true } ], "status_key" : "ACTIVE", "start_date_key" : { "$date" : "2015-01-29T03:50:28.000-0300" } }

{ "_id" : { [ { "avps_key" : [], "enabled_key" : true, "code_key" : "IM_Prepago" }, { "avps_key" : null, "enabled_key" : true, "code_key" : "TDE_IM_PP" }, { "code_key" : "TDE_ROAM_DEF", "avps_key" : null, "enabled_key" : true } ], "status_key" : "ACTIVE", "start_date_key" : { "$date" : "2015-01-29T03:50:28.000-0300" } }

alt text

0 Karma

Sukisen1981
Champion

As @ cpetterborg says

If you are trying this at search time all you need to do is add a max_match=0 after your regex, assuming your regex is giving the correct value for 1 extraction... something like `rex field=_raw "(code_key)"\s*:\s*"?(?[\w\d:.-]*?)" max_match=0. Has your rejected got corrupted while pasting here?Bsically just pipe max_match after the regex that successfully extracts the first value.

0 Karma

efaundez
Path Finder

thanks for your reply
  
   Splunk continues only taking into account 1 only value and the others ignore them 😞

alt text

alt text

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

Again - Are you wanting to do this at search time (in the search string - e.g.rex, or auto field extraction), or at index time?

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

So you are getting ONLY the first match and not the other two, but you want all three?

And are you wanting to do this at search time (in the search string - e.g.rex, or auto field extraction), or at index time?

Also, for clarity - your regex seems to have gotten a little eaten by the formatting:

"(code_key)"\s*:\s*"?(?<code_key>[\w\d\:.-]*)"?

I also took a few backslashes out that weren't needed.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Your Path to AgenticOps: AI Experiences for Every Splunk Practitioner

Your Path to AgenticOps: AI Experiences for Every Splunk Practitioner   Watch on demand us for a demo-driven ...

The Data Connection - October 2026

We all have data. Lots of it. But that’s not the problem – it’s understanding what we should we do with it, ...

Beyond the Acceleration Zone: Maximizing Your Success with Splunk Customer Experience ...

Customer success is built on tailored guidance and accessible resources. As a Splunk user, you are encouraged ...