<?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 extract key, field name, and value with regex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253317#M75797</link>
    <description>&lt;P&gt;Yes, I have done this, not with a variable delimiter, but I think a field transform will work. &lt;/P&gt;

&lt;P&gt;I used this for logs with ]:[ key-value delimiter and ] [ as pair delimiter, e.g. [KEY1]:[VALUE1] [KEY2]:[VALUE2] [KEY3.....&lt;/P&gt;

&lt;P&gt;From webui for example above... &lt;/P&gt;

&lt;P&gt;Create Transform...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Fields--&amp;gt;Field Transformations--New
Regular Expression: \[([a-zA-Z0-9_]*?)\]\:\[([^\]]*?)\]
Source Key: _raw
Format: $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Create Extract&lt;BR /&gt;
Then create new field extract, choose Type of transform, and point to the transform you created.&lt;/P&gt;

&lt;P&gt;Tip: use regex101.com or equivalent to test your regex... it will work there and in transform but I get errors using this inline.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Dec 2016 11:25:47 GMT</pubDate>
    <dc:creator>snoobzilla</dc:creator>
    <dc:date>2016-12-02T11:25:47Z</dc:date>
    <item>
      <title>How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253310#M75790</link>
      <description>&lt;P&gt;I'm wondering if somebody had faced this freaking behavior.&lt;/P&gt;

&lt;P&gt;I wanna extract both key, the field name, and its value from my (pretty uncommon) log and, in order to this I did the following:&lt;/P&gt;

&lt;P&gt;In first place I made the search bellow just to test the regex, and it's working perfectly.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | rex max_match=0 field=_raw "(?&amp;lt;test1&amp;gt;\w+)\(.+\)=(?&amp;lt;test2&amp;gt;[^\(].*)[\n|\r]"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I then replaced the test1 and test2 tags by _KEY_1 and _VAL_1 to assign properly each matched group to key and value as I wanted.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | rex max_match=0 field=_raw "(?&amp;lt;_KEY_1&amp;gt;\w+)\(.+\)=(?&amp;lt;_VAL_1&amp;gt;[^\(].*)[\n|\r]"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;From here ahead the extraction didn't work anymore.&lt;/P&gt;

&lt;P&gt;So, had someone handled successfully same problem using this _KEY_1 and _VAL_1 tags? It seems like a bug for me.&lt;/P&gt;

&lt;P&gt;Thanks in advance,&lt;/P&gt;

&lt;P&gt;Tiago&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:57:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253310#M75790</guid>
      <dc:creator>tcmarquesi</dc:creator>
      <dc:date>2020-09-29T11:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253311#M75791</link>
      <description>&lt;P&gt;Leading underscores on field names is a no-no. Splunk uses leading underscores on field names for special / hidden fields.&lt;/P&gt;

&lt;P&gt;Try renaming your fields to something with no leading underscore.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 20:53:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253311#M75791</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2016-12-01T20:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253312#M75792</link>
      <description>&lt;P&gt;Here is a link with more details about internal fields. &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.1/Knowledge/Usedefaultfields"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.1/Knowledge/Usedefaultfields&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 20:54:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253312#M75792</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2016-12-01T20:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253313#M75793</link>
      <description>&lt;P&gt;Splunk regex does not like &lt;CODE&gt;_&lt;/CODE&gt; in field names. Having said that, have your looked at the &lt;CODE&gt;extract&lt;/CODE&gt; command, that may be a better options.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | extract kvdelim="=" pairdelim="\n"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Extract"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Extract&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 20:56:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253313#M75793</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-12-01T20:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253314#M75794</link>
      <description>&lt;P&gt;You need to do this using a field transform and reference that transform in a field extraction. I can get these working on regex101.com but have not had luck using them inline.&lt;/P&gt;

&lt;P&gt;See &lt;A href="https://answers.splunk.com/answers/126754/transforms-field-value-extract-not-fully-working.html"&gt;https://answers.splunk.com/answers/126754/transforms-field-value-extract-not-fully-working.html&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 20:56:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253314#M75794</guid>
      <dc:creator>snoobzilla</dc:creator>
      <dc:date>2016-12-01T20:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253315#M75795</link>
      <description>&lt;P&gt;Just few additional comments:&lt;/P&gt;

&lt;P&gt;I need to use regex because my log is a little unusual, it can't be automatically parsed.&lt;/P&gt;

&lt;P&gt;I don't want to change my log with sed or something like that, is important to me keep it original.&lt;/P&gt;

&lt;P&gt;In fact I intend to implement it in transforms.conf. I made the question using the SPL search because it behaved equally and it's easier to be reproduced.&lt;/P&gt;

&lt;P&gt;Regards,&lt;/P&gt;

&lt;P&gt;Tiago&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 20:56:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253315#M75795</guid>
      <dc:creator>tcmarquesi</dc:creator>
      <dc:date>2016-12-01T20:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253316#M75796</link>
      <description>&lt;P&gt;Thanks, but you missed my log is not that simple. Between key and value there is some text like "(foo 12)=". So I have to use regex, extract is ineffective.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 09:34:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253316#M75796</guid>
      <dc:creator>tcmarquesi</dc:creator>
      <dc:date>2016-12-02T09:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253317#M75797</link>
      <description>&lt;P&gt;Yes, I have done this, not with a variable delimiter, but I think a field transform will work. &lt;/P&gt;

&lt;P&gt;I used this for logs with ]:[ key-value delimiter and ] [ as pair delimiter, e.g. [KEY1]:[VALUE1] [KEY2]:[VALUE2] [KEY3.....&lt;/P&gt;

&lt;P&gt;From webui for example above... &lt;/P&gt;

&lt;P&gt;Create Transform...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Fields--&amp;gt;Field Transformations--New
Regular Expression: \[([a-zA-Z0-9_]*?)\]\:\[([^\]]*?)\]
Source Key: _raw
Format: $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Create Extract&lt;BR /&gt;
Then create new field extract, choose Type of transform, and point to the transform you created.&lt;/P&gt;

&lt;P&gt;Tip: use regex101.com or equivalent to test your regex... it will work there and in transform but I get errors using this inline.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 11:25:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253317#M75797</guid>
      <dc:creator>snoobzilla</dc:creator>
      <dc:date>2016-12-02T11:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253318#M75798</link>
      <description>&lt;P&gt;Just to stay everybody in the same page, using "_" is not a problem, indeed both &lt;CODE&gt;_KEY_foo&lt;/CODE&gt; and &lt;CODE&gt;_VAL_bar&lt;/CODE&gt; are reserved tags in order to allow splunk find the field name a its value into the text, as in docs.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.0/Data/Configureindex-timefieldextraction#Add_a_regex_stanza_for_the_new_field_to_transforms.conf" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.0/Data/Configureindex-timefieldextraction#Add_a_regex_stanza_for_the_new_field_to_transforms.conf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:58:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253318#M75798</guid>
      <dc:creator>tcmarquesi</dc:creator>
      <dc:date>2020-09-29T11:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253319#M75799</link>
      <description>&lt;P&gt;I'd done this but through &lt;EM&gt;transforms.conf&lt;/EM&gt;. Indeed I can see my stanza through UI.&lt;/P&gt;

&lt;P&gt;About the regex, I tested it exhaustively in both regex101.com and regexr.com/v1, and it's working perfectly.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 12:38:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253319#M75799</guid>
      <dc:creator>tcmarquesi</dc:creator>
      <dc:date>2016-12-02T12:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253320#M75800</link>
      <description>&lt;P&gt;Did you try method above with your rex without named capturing groups at all?... e.g. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(\w+)\(.+\)=([^\(].*)[\n|\r]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note the Format field in transform: $1::$2&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 12:54:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253320#M75800</guid>
      <dc:creator>snoobzilla</dc:creator>
      <dc:date>2016-12-02T12:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253321#M75801</link>
      <description>&lt;P&gt;Or maybe&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(\w+?)\(.+\)=([^\(].*?)[\n|\r]  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Dec 2016 12:55:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253321#M75801</guid>
      <dc:creator>snoobzilla</dc:creator>
      <dc:date>2016-12-02T12:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253322#M75802</link>
      <description>&lt;P&gt;Yes, I did. It was my starting point.&lt;/P&gt;

&lt;P&gt;This issue really seems as a bug for me...&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 12:58:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253322#M75802</guid>
      <dc:creator>tcmarquesi</dc:creator>
      <dc:date>2016-12-02T12:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253323#M75803</link>
      <description>&lt;P&gt;Bummer. You may be right, may be a limitation.&lt;/P&gt;

&lt;P&gt;Assume you saw this...  &lt;A href="https://answers.splunk.com/answers/133561/multiple-key-value-pair-extraction.html"&gt;https://answers.splunk.com/answers/133561/multiple-key-value-pair-extraction.html&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 13:11:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253323#M75803</guid>
      <dc:creator>snoobzilla</dc:creator>
      <dc:date>2016-12-02T13:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253324#M75804</link>
      <description>&lt;P&gt;Thanks all help. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 15:21:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253324#M75804</guid>
      <dc:creator>tcmarquesi</dc:creator>
      <dc:date>2016-12-02T15:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253325#M75805</link>
      <description>&lt;P&gt;Late to the party here, but I had a similar need to this and saw that this question hadn't been answered. Basically do your extractions, then use {} in an eval to have a variable fieldname. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-2
| eval _raw="extract"+starttime+" this"+endtime
| rex field=_raw "(?&amp;lt;field_name&amp;gt;extract[0-9]+)\s(?&amp;lt;field_value&amp;gt;this[0-9]+)"
| eval {field_name}=field_value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then if you care, you can get rid of the placeholder fields: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-2
| fields - *human
| eval _raw="extract"+starttime+" this"+endtime
| rex field=_raw "(?&amp;lt;field_name&amp;gt;extract[0-9]+)\s(?&amp;lt;field_value&amp;gt;this[0-9]+)"
| eval {field_name}=field_value
| fields - field_name field_value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These searches should run anywhere. The idea came from here &lt;A href="https://answers.splunk.com/answers/103700/how-do-i-create-a-field-whose-name-is-the-value-of-another-field-like-backticks-or-eval-in-other-languages.html"&gt;https://answers.splunk.com/answers/103700/how-do-i-create-a-field-whose-name-is-the-value-of-another-field-like-backticks-or-eval-in-other-languages.html&lt;/A&gt;. &lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 22:03:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/253325#M75805</guid>
      <dc:creator>aguthrie1190</dc:creator>
      <dc:date>2019-02-07T22:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract key, field name, and value with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/522658#M147386</link>
      <description>&lt;P&gt;Maybe, not working with _KEY_1 and _VALUE_1 because of splunk&amp;nbsp;reserves the fields beginning with _ for your own settings, if I remember correctly.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 11:46:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-key-field-name-and-value-with-regex/m-p/522658#M147386</guid>
      <dc:creator>irenefdezbb</dc:creator>
      <dc:date>2020-10-02T11:46:38Z</dc:date>
    </item>
  </channel>
</rss>

