<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to write a regular expression to extract key value pairs from my sample event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235580#M69941</link>
    <description>&lt;P&gt;Try this one:&lt;/P&gt;

&lt;P&gt;REGEX= (?ism)"(\w+)":"([^"]+)|timestamp":(?P\d+)&lt;BR /&gt;
FORMAT = $1:$2&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2016 19:56:58 GMT</pubDate>
    <dc:creator>sshelly_splunk</dc:creator>
    <dc:date>2016-11-22T19:56:58Z</dc:date>
    <item>
      <title>How to write a regular expression to extract key value pairs from my sample event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235574#M69935</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;We have events which contain key value pairs separated by a colon &lt;CODE&gt;:&lt;/CODE&gt;.&lt;BR /&gt;
Here is the sample event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;6&amp;gt;2016-11-22T16:29:37Z v26l5klvoo3 doppler[21]: {"cf_app_id":"19351f6f-d125-4322-88ed-926e8f578e16","cf_app_name":"nam-rds-gpu-drag-payment-mq","cf_org_id":"d58e8896-6150-4f89-806b-c28464ba7e22","cf_org_name":"NAM-US-verizon","cf_origin":"firehorse","cf_space_id":"52223ed6-a3c5-4955-a6f8-be6c9649e215","cf_space_name":"RDS-DEV1","event_type":"LogMessage","level":"info","message_type":"OUT","msg":"[2016-11-22 16:29:37,017] DiscoveryClient-CacheRefreshExecutor-0 (DiscoveryClient.java:1064) DEBUG - Got delta update with apps hashcode UP_45_","origin":"rep","source_instance":"0","source_type":"APP","time":"2016-11-22T16:29:37Z","timestamp":1479832177017862007}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Key value pairs are with in curly brackets &lt;CODE&gt;{ }&lt;/CODE&gt;&lt;BR /&gt;
Example: cf_space_name":"RDS-DEV1"  this is one key value pair&lt;/P&gt;

&lt;P&gt;Can you please help us to write a regular expression for the above sample event.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:51:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235574#M69935</guid>
      <dc:creator>rajgowd1</dc:creator>
      <dc:date>2020-09-29T11:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a regular expression to extract key value pairs from my sample event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235575#M69936</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;REGEX = "([^"]+)":"([^"]+)
FORMAT = $1:$2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2016 16:58:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235575#M69936</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-11-22T16:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a regular expression to extract key value pairs from my sample event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235576#M69937</link>
      <description>&lt;P&gt;Hi Sundaresh,&lt;BR /&gt;
when i try &lt;CODE&gt;index=myindex | rex "([^"]+)":"([^"]+)&lt;/CODE&gt;&lt;BR /&gt;
getting error like Mismatched ']'.  but the same expression is working in regex101&lt;/P&gt;

&lt;P&gt;am i missing any here?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 17:31:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235576#M69937</guid>
      <dc:creator>rajgowd1</dc:creator>
      <dc:date>2016-11-22T17:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a regular expression to extract key value pairs from my sample event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235577#M69938</link>
      <description>&lt;P&gt;Apologies @sundareshr and @rajgowd1 I accidentally clicked the Accept button. I unaccepted it since this question is still unresolved.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 18:13:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235577#M69938</guid>
      <dc:creator>ppablo</dc:creator>
      <dc:date>2016-11-22T18:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a regular expression to extract key value pairs from my sample event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235578#M69939</link>
      <description>&lt;P&gt;If you're using it in rex, you'll need to escape the quote. Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "\"(?&amp;lt;key&amp;gt;[^\"]+)\":\"(?&amp;lt;value&amp;gt;[^\"]+)" max_match=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With this, &lt;CODE&gt;key&lt;/CODE&gt; and &lt;CODE&gt;value&lt;/CODE&gt; will be mvfields, to access a specific value, you will have to use &lt;CODE&gt;mvindex(key, n)&lt;/CODE&gt; etc. I would not recommed this approach. &lt;/P&gt;

&lt;P&gt;The other thing you could try is the extract command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | extract kvdelim=":" pairdelim=","
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This may work better for your case&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Extract"&gt;https://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Extract&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 18:16:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235578#M69939</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-11-22T18:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a regular expression to extract key value pairs from my sample event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235579#M69940</link>
      <description>&lt;P&gt;thank you.you are genius.regular expression and extract both are working as expected&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 18:26:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235579#M69940</guid>
      <dc:creator>rajgowd1</dc:creator>
      <dc:date>2016-11-22T18:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a regular expression to extract key value pairs from my sample event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235580#M69941</link>
      <description>&lt;P&gt;Try this one:&lt;/P&gt;

&lt;P&gt;REGEX= (?ism)"(\w+)":"([^"]+)|timestamp":(?P\d+)&lt;BR /&gt;
FORMAT = $1:$2&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 19:56:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-regular-expression-to-extract-key-value-pairs/m-p/235580#M69941</guid>
      <dc:creator>sshelly_splunk</dc:creator>
      <dc:date>2016-11-22T19:56:58Z</dc:date>
    </item>
  </channel>
</rss>

