<?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 Regex for items in single quotes in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357484#M105733</link>
    <description>&lt;P&gt;I have a bunch of logs which look like the following.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2017-05-01 18:36:16,885 UTC - DEBUG - testpod_service.segment_processor - [BTESTC4277:37223] returning requests="[{'status': 'request_automat_eventab', 'priority': -2868.565, 'confidence': 1.0, 'db': {'dur_sec': 2868.565, 'n_hours': 2}, 'onset': 66377515, 'event_name': 'CYCLE', 'offset': 66951227
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For every segment that looks like &lt;CODE&gt;'field':'value'&lt;/CODE&gt;I want Splunk to treat the value in quotes BEFORE the &lt;CODE&gt;:&lt;/CODE&gt; as the field name and the value in quotes AFTER the &lt;CODE&gt;:&lt;/CODE&gt; as the value for the field (similar treatment to &lt;CODE&gt;field="value"&lt;/CODE&gt;, which is Splunk's default).&lt;/P&gt;

&lt;P&gt;How do I achieve this through a regex treatment? For example, in the example above, I'd like my field and value pairs to be as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;status = request_automat_eventab
priority = -2868.565
confidence = 1.0
dur_sec=2868.565
n_hours=2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...and so on&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Mon, 01 May 2017 21:30:00 GMT</pubDate>
    <dc:creator>aramakrishnan</dc:creator>
    <dc:date>2017-05-01T21:30:00Z</dc:date>
    <item>
      <title>Regex for items in single quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357484#M105733</link>
      <description>&lt;P&gt;I have a bunch of logs which look like the following.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2017-05-01 18:36:16,885 UTC - DEBUG - testpod_service.segment_processor - [BTESTC4277:37223] returning requests="[{'status': 'request_automat_eventab', 'priority': -2868.565, 'confidence': 1.0, 'db': {'dur_sec': 2868.565, 'n_hours': 2}, 'onset': 66377515, 'event_name': 'CYCLE', 'offset': 66951227
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For every segment that looks like &lt;CODE&gt;'field':'value'&lt;/CODE&gt;I want Splunk to treat the value in quotes BEFORE the &lt;CODE&gt;:&lt;/CODE&gt; as the field name and the value in quotes AFTER the &lt;CODE&gt;:&lt;/CODE&gt; as the value for the field (similar treatment to &lt;CODE&gt;field="value"&lt;/CODE&gt;, which is Splunk's default).&lt;/P&gt;

&lt;P&gt;How do I achieve this through a regex treatment? For example, in the example above, I'd like my field and value pairs to be as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;status = request_automat_eventab
priority = -2868.565
confidence = 1.0
dur_sec=2868.565
n_hours=2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...and so on&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 21:30:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357484#M105733</guid>
      <dc:creator>aramakrishnan</dc:creator>
      <dc:date>2017-05-01T21:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for items in single quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357485#M105734</link>
      <description>&lt;P&gt;Are you asking about at index time or at search time?&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 00:22:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357485#M105734</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-02T00:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for items in single quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357486#M105735</link>
      <description>&lt;P&gt;use the field extractor from GUIi? click an event -&amp;gt; actions -&amp;gt; extract fields -&amp;gt; new tab pops -&amp;gt; follow the prompts -&amp;gt; save -&amp;gt; search your fields&lt;BR /&gt;
read more here:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.3/Knowledge/ExtractfieldsinteractivelywithIFX"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.3/Knowledge/ExtractfieldsinteractivelywithIFX&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 00:25:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357486#M105735</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2017-05-02T00:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for items in single quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357487#M105736</link>
      <description>&lt;P&gt;If the field / value format is consistent, you can use &amp;lt;_KEY_1&amp;gt; and &amp;lt;_VAL_1&amp;gt; as your field names in your capture groups to dynamically extract all field value pairs.  In your props.conf, under the sourcetype for these events add a field extraction like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yoursourcetypehere]
EXTRACT-keysandvals = \"\[{\'(?&amp;lt;_KEY_1&amp;gt;\S+)\': \'(?&amp;lt;_VAL_1&amp;gt;\S+)\'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You may have to play with the regex a bit, but this should work.  It will take everything in single quotes before the colon as a field name and everything after the colon in single quotes as the value for that field.  You can use this any time you have a consistent format for the pairs. &lt;/P&gt;

&lt;P&gt;I had a customer example where the field was in brackets followed by the value:&lt;/P&gt;

&lt;P&gt;[fieldname1]fieldvalue1[fieldname2]fieldvalue2&lt;/P&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:54:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357487#M105736</guid>
      <dc:creator>kmorris_splunk</dc:creator>
      <dc:date>2020-09-29T13:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for items in single quotes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357488#M105737</link>
      <description>&lt;P&gt;You can use the _KEY_1 and _VAL_1 field names in your regex capture groups to get all of the key value pairs dynamically.  For example, in your props.conf, under the sourcetype for these events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yoursourcetype]
EXTRACT-keysandvalues = \"\[{\'(?&amp;lt;_KEY_1&amp;gt;\S+)\': \'(?&amp;lt;_VAL_1&amp;gt;\S+)\'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will take every value in single quotes before the colon as the field name and the value in single quotes after the colon as the value for that field.  This will work for any format you can match in the extractions regex.  As long as the key value pairs are consistent, it will grab them all.&lt;/P&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:54:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-items-in-single-quotes/m-p/357488#M105737</guid>
      <dc:creator>kmorris_splunk</dc:creator>
      <dc:date>2020-09-29T13:54:29Z</dc:date>
    </item>
  </channel>
</rss>

