<?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 the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172712#M49516</link>
    <description>&lt;P&gt;Extracted both values comes after "Received:" and "X-Received:" in the same field. Here is the regex saved. &lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/lI4kZ4/1"&gt;https://regex101.com/r/lI4kZ4/1&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;please let me know if you need any changes, I shall modify the regex accordingly.&lt;/P&gt;

&lt;P&gt;Also, please answer my questions posted as commented to your question. &lt;/P&gt;</description>
    <pubDate>Sun, 04 Jan 2015 20:21:43 GMT</pubDate>
    <dc:creator>jayannah</dc:creator>
    <dc:date>2015-01-04T20:21:43Z</dc:date>
    <item>
      <title>How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172710#M49514</link>
      <description>&lt;P&gt;I have events that look like this.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://pastebin.com/w8a3WTe6" target="_blank"&gt;Example 1.&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://pastebin.com/RnRDb0pA" target="_blank"&gt;Example 2.&lt;/A&gt;&lt;BR /&gt;
.......&lt;/P&gt;

&lt;P&gt;I have indexed the data using a props.conf like thisL&lt;/P&gt;

&lt;P&gt;[gmail-mbox]&lt;BR /&gt;
MAX_EVENTS = 10000&lt;BR /&gt;
BREAK_ONLY_BEFORE = From\s.+?@&lt;BR /&gt;
MAX_TIMESTAMP_LOOKAHEAD = 150&lt;BR /&gt;
NO_BINARY_CHECK = 1&lt;BR /&gt;
TRUNCATE = 10000&lt;BR /&gt;
pulldown_type = 1&lt;/P&gt;

&lt;P&gt;Now trying to exact fields from each event. I am only interested in the fields:&lt;/P&gt;

&lt;P&gt;X-Gmail-Labels:&lt;BR /&gt;
Delivered-To:&lt;BR /&gt;
Subject:&lt;BR /&gt;
From&lt;/P&gt;

&lt;P&gt;The field name can be seen before a colon.&lt;/P&gt;

&lt;P&gt;The field value is everything after the colon and on the same line (for the above extractions).&lt;/P&gt;

&lt;P&gt;How can I write a regex to extract fields in this format? Note, field values may also contain colons.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:33:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172710#M49514</guid>
      <dc:creator>himynamesdave</dc:creator>
      <dc:date>2020-09-28T18:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172711#M49515</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Can you please put one complete event log how it looks?&lt;/LI&gt;
&lt;LI&gt;Do intended to extract the value after "Received:" and "X-Received" in to the same field name or different field name?&lt;/LI&gt;
&lt;LI&gt;What is your event line break format?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sun, 04 Jan 2015 20:12:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172711#M49515</guid>
      <dc:creator>jayannah</dc:creator>
      <dc:date>2015-01-04T20:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172712#M49516</link>
      <description>&lt;P&gt;Extracted both values comes after "Received:" and "X-Received:" in the same field. Here is the regex saved. &lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/lI4kZ4/1"&gt;https://regex101.com/r/lI4kZ4/1&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;please let me know if you need any changes, I shall modify the regex accordingly.&lt;/P&gt;

&lt;P&gt;Also, please answer my questions posted as commented to your question. &lt;/P&gt;</description>
      <pubDate>Sun, 04 Jan 2015 20:21:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172712#M49516</guid>
      <dc:creator>jayannah</dc:creator>
      <dc:date>2015-01-04T20:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172713#M49517</link>
      <description>&lt;P&gt;Thanks for the help - I really appreciate it.&lt;/P&gt;

&lt;P&gt;I have updated the question, if this helps?&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jan 2015 23:03:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172713#M49517</guid>
      <dc:creator>himynamesdave</dc:creator>
      <dc:date>2015-01-04T23:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172714#M49518</link>
      <description>&lt;P&gt;Based on your new updated log, here are the extractions..&lt;/P&gt;

&lt;P&gt;If you are sure that event is having the 4 fields you mentioned, then you can use the single regex mentioned in the below URL&lt;BR /&gt;
&lt;A href="https://regex101.com/r/cJ5vW2/1"&gt;https://regex101.com/r/cJ5vW2/1&lt;/A&gt;&lt;BR /&gt;
P.S : If any one of above 4 mentioned fields is missing, then this regex may not extract for those events. &lt;/P&gt;

&lt;P&gt;If you are not sure if these fields are existing in every event mandatorily, then better I would suggest to use individual extraction for each fields..&lt;/P&gt;

&lt;P&gt;Extraction for X-Gmail-Labels : &lt;A href="https://regex101.com/r/cJ5vW2/2"&gt;https://regex101.com/r/cJ5vW2/2&lt;/A&gt;&lt;BR /&gt;
Extraction for Delivered-To :   &lt;A href="https://regex101.com/r/cJ5vW2/3"&gt;https://regex101.com/r/cJ5vW2/3&lt;/A&gt;&lt;BR /&gt;
Extraction for Subject : &lt;A href="https://regex101.com/r/cJ5vW2/4"&gt;https://regex101.com/r/cJ5vW2/4&lt;/A&gt;&lt;BR /&gt;
Extraction for From : &lt;A href="https://regex101.com/r/cJ5vW2/5"&gt;https://regex101.com/r/cJ5vW2/5&lt;/A&gt;&lt;BR /&gt;
If you want extract name and email id from From field seperately : &lt;A href="https://regex101.com/r/cJ5vW2/6"&gt;https://regex101.com/r/cJ5vW2/6&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;These individual extraction works fine event if one of 4 fields missing in any of events.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2015 03:40:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172714#M49518</guid>
      <dc:creator>jayannah</dc:creator>
      <dc:date>2015-01-05T03:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172715#M49519</link>
      <description>&lt;P&gt;For some reason these extractions capture the event from the start of the specified field to the end of the complete event (capturing everything after the field).&lt;/P&gt;

&lt;P&gt;Strangely, when I paste this regex in the field extractor in Splunk GUI the extractions work correctly in the test mode, but fail again when extraction is saved and a search is run. &lt;/P&gt;

&lt;P&gt;Any ideas why this might be?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2015 10:55:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172715#M49519</guid>
      <dc:creator>himynamesdave</dc:creator>
      <dc:date>2015-01-05T10:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172716#M49520</link>
      <description>&lt;P&gt;I think that is becos your event in splunk doesn't have the new line character . Can you please put the extracted values after regex are saved for the above 4 parameters with for an event?&lt;/P&gt;

&lt;P&gt;Did you use the single regex for all fields or individual regex?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2015 14:05:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172716#M49520</guid>
      <dc:creator>jayannah</dc:creator>
      <dc:date>2015-01-05T14:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172717#M49521</link>
      <description>&lt;P&gt;Check if this helps &lt;A href="https://regex101.com/r/cJ5vW2/7"&gt;https://regex101.com/r/cJ5vW2/7&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;ALso, I removed all the new line characters and still my regex works fine.. please see here &lt;A href="https://regex101.com/r/cJ5vW2/8"&gt;https://regex101.com/r/cJ5vW2/8&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;please let me know if you are still facing any issues&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2015 14:06:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172717#M49521</guid>
      <dc:creator>jayannah</dc:creator>
      <dc:date>2015-01-05T14:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172718#M49522</link>
      <description>&lt;P&gt;I used the individual regex. Take for example "X-Gmail-Labels\s*:\s*(?P.+)"&lt;/P&gt;

&lt;P&gt;Using the event in example 1 in the question, I get the following extraction for "X_Gmail_Labels" &lt;A href="http://pastebin.com/mwPkakz1" target="_blank"&gt;http://pastebin.com/mwPkakz1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;However, when I run the regex in a search (sourcetype="gmail-mbox" | head 10000 | rex "X-Gmail-Labels\s*:\s*(?P.+)" | top 50 X_Gmail_Labels) all the fields are extracted as expected.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:34:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172718#M49522</guid>
      <dc:creator>himynamesdave</dc:creator>
      <dc:date>2020-09-28T18:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172719#M49523</link>
      <description>&lt;P&gt;Sorry, the URL you mentioned is blocked in office. &lt;/P&gt;

&lt;P&gt;Can you please try this &lt;A href="https://regex101.com/r/cJ5vW2/9"&gt;https://regex101.com/r/cJ5vW2/9&lt;/A&gt; on saved regex and let me know?&lt;/P&gt;

&lt;P&gt;Generally it should work whether you saved the rex or used in search query and should be same.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2015 16:46:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172719#M49523</guid>
      <dc:creator>jayannah</dc:creator>
      <dc:date>2015-01-05T16:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172720#M49524</link>
      <description>&lt;P&gt;The most efficient way to do the extraction in splunk is to use the REPORT feature and a transforms.conf entry.&lt;/P&gt;

&lt;P&gt;props.conf&lt;BR /&gt;
&lt;CODE&gt;[gmail-mbox]&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;REPORT-extract-headers = extract-headers&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;transforms.conf&lt;BR /&gt;
&lt;CODE&gt;[extract-headers]&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;REGEX = ^([^:]+):([^\r\n]+)&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;FORMAT = $1::$2&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Or if you want to make it specific to just those headers mentioned you can make it explicit as such.&lt;/P&gt;

&lt;P&gt;transforms.conf&lt;BR /&gt;
&lt;CODE&gt;[extract-headers]&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;REGEX = ^(X-Gmail-Labels|Delivered-To|Subject|From):([^\r\n]+)&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;FORMAT = $1::$2&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;That should grab the fields and values in one repeatable operation.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jan 2015 04:34:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172720#M49524</guid>
      <dc:creator>eddit0r</dc:creator>
      <dc:date>2015-01-06T04:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex for field extractions of key-value pairs in the format FIELD:VALUE from multiline events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172721#M49525</link>
      <description>&lt;P&gt;Assuming the sample logs break out at a new line as provided, i tried replicating a piece of it. Hope this helps&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|gentimes start=-1 
|eval _raw = "X-Gmail-Labels: Sent,Important 
MIME-Version: 1.0 
Received: by 10.52.29.70 with HTTP; Sun, 28 Dec 2014 16:11:00 -0800 (PST) 
X-Originating-IP: [82.13.144.221] 
In-Reply-To: &amp;lt;01ff42fddfded95cfa8b14fa5559b0fb.squirrel@webmail04.register.com&amp;gt;"|extract pairdelim="\n",kvdelim=":"|table *

This extracted all the fields. pairdelim is set to break at \n(newline) and key value pairs with ':'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Raghav&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jan 2015 23:13:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-for-field-extractions-of-key-value-pairs/m-p/172721#M49525</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2015-01-07T23:13:40Z</dc:date>
    </item>
  </channel>
</rss>

