<?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 create a regex field extraction for the last occurence for a specific text? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435781#M124238</link>
    <description>&lt;P&gt;No specific drawback of benefit. Just easier to read, but that is perhaps also personal preference &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jun 2019 09:32:17 GMT</pubDate>
    <dc:creator>FrankVl</dc:creator>
    <dc:date>2019-06-20T09:32:17Z</dc:date>
    <item>
      <title>How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435774#M124231</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;We have attached log file.&lt;A href="https://community.splunk.com/storage/temp/273032-sample-log.txt" target="_blank"&gt;link text&lt;/A&gt; The whole log file contains in one single event in splunk.&lt;BR /&gt;
Now, I need to extract data(filename, date, time) from only last lines of text.&lt;BR /&gt;
ex:&lt;BR /&gt;
&lt;STRONG&gt;Try upload file : &lt;BR /&gt;
Upload File D:\Program Files\X529\Matrix IT Software PK\PTS\Files\JobLettrers\BAAppointmentLetters_2016_4_9_13_0.csv Complete, status : 226 Transfer complete.&lt;BR /&gt;
Closing log at 2:00:56 PM on 4/29/2016&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;to extract this I tried with my below SPL:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    index="main" source="Sample_log.txt" | rex field=log "Try upload file : (?&amp;lt;file&amp;gt;.*)\nUpload File (?&amp;lt;msg&amp;gt;.*)([\S\s\n]*)\nClosing log at (?&amp;lt;time&amp;gt;.*) on (?&amp;lt;date&amp;gt;.*)" | table file msg  time date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but this regex is not working as it capture many of line of text in &lt;STRONG&gt;log&lt;/STRONG&gt; field and consider the only first one.&lt;A href="https://community.splunk.com/storage/temp/273032-sample-log.txt" target="_blank"&gt;link text&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Please suggest. Thanks.&lt;/P&gt;

&lt;P&gt;Dhirendra&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:00:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435774#M124231</guid>
      <dc:creator>dhirendra761</dc:creator>
      <dc:date>2020-09-30T01:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435775#M124232</link>
      <description>&lt;P&gt;That's because you're using way to generic matchings in your regex. See: &lt;A href="https://regex101.com/r/o0Bm3F/1"&gt;https://regex101.com/r/o0Bm3F/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Especially &lt;CODE&gt;([\S\s\n]*)&lt;/CODE&gt; which matches non-whitespace and whitespace and newline (which is also contained in whitespace as well), so basically matches anything. You will need to make your regex more specific to have it only match the last line.&lt;/P&gt;

&lt;P&gt;Also your capture groups don't seem to be in the right place (the filename comes after the "Upload File" text, not before. Not entirely sure what you want to capture in the msg field.&lt;/P&gt;

&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="main" source="Sample_log.txt" | rex field=log "Try upload file :\s+Upload File (?&amp;lt;file&amp;gt;.*?)\s+(?&amp;lt;msg&amp;gt;\w+,[^.]+\.)\s+Closing log at (?&amp;lt;time&amp;gt;\d+:\d+:\d+\s+\w+) on (?&amp;lt;date&amp;gt;\d+\/\d+\/\d+)" | table file msg  time date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See also: &lt;A href="https://regex101.com/r/Yw0rpg/1"&gt;https://regex101.com/r/Yw0rpg/1&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 07:49:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435775#M124232</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-06-20T07:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435776#M124233</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Please try below regex.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| regex field=&amp;lt;yourfield&amp;gt; "Try[^\:]+\:\s(?&amp;lt;file&amp;gt;[^\v]+)?\vUpload\sFile\s(?&amp;lt;msg&amp;gt;[^\.]+\.[^\s]+\s[^\v]+)\v{2}Closing[^\d]+(?&amp;lt;time&amp;gt;[^on]+)on\s(?&amp;lt;date&amp;gt;[^\$]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Regex101: &lt;A href="https://regex101.com/r/vqfSMz/1"&gt;https://regex101.com/r/vqfSMz/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;EDIT: Updated regex and removed &lt;CODE&gt;()&lt;/CODE&gt; from &lt;CODE&gt;(?&amp;lt;time&amp;gt;[^(on)]+)&lt;/CODE&gt; , credit goes to @FrankVl &lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 08:43:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435776#M124233</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-20T08:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435777#M124234</link>
      <description>&lt;P&gt;Did you test that? Cause it doesn't work: &lt;A href="https://regex101.com/r/vlXUdG/1"&gt;https://regex101.com/r/vlXUdG/1&lt;/A&gt;&lt;BR /&gt;
Capture groups are not in the right spot and there is no newline after the filename.&lt;/P&gt;

&lt;P&gt;Also &lt;CODE&gt;[^(on)]&lt;/CODE&gt;is a bit of a strange notation. The &lt;CODE&gt;()&lt;/CODE&gt; are pointless there. (and I could make similar comments on some of your other regex syntax.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 08:49:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435777#M124234</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-06-20T08:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435778#M124235</link>
      <description>&lt;P&gt;I didn't tested that in Splunk only on regex101, &lt;CODE&gt;[^(on)]&lt;/CODE&gt; yes that is strange one but there are no difference if you remove &lt;CODE&gt;()&lt;/CODE&gt; or keep it in regex it will still use same steps to capture the result. You are most welcome to comment on my other regex as well. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 08:53:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435778#M124235</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-20T08:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435779#M124236</link>
      <description>&lt;P&gt;So in regex101 you noticed it is not capturing the filename and putting both filename and status info into the msg field?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;[^(on)]&lt;/CODE&gt; : there is very much difference between including the &lt;CODE&gt;()&lt;/CODE&gt; or not. Not for this sample data, but including the &lt;CODE&gt;()&lt;/CODE&gt; means match any charachter not equal to &lt;CODE&gt;(&lt;/CODE&gt;, &lt;CODE&gt;o&lt;/CODE&gt;,&lt;CODE&gt;n&lt;/CODE&gt; or &lt;CODE&gt;)&lt;/CODE&gt;. Without the &lt;CODE&gt;()&lt;/CODE&gt; it just means match any character not equal to &lt;CODE&gt;o&lt;/CODE&gt; or &lt;CODE&gt;n&lt;/CODE&gt;.&lt;BR /&gt;
&lt;CODE&gt;[^\.]&lt;/CODE&gt; : no backslash needed when you use &lt;CODE&gt;.&lt;/CODE&gt; inside a character class definition.&lt;BR /&gt;
&lt;CODE&gt;[^\v]&lt;/CODE&gt; &lt;CODE&gt;[^\s]&lt;/CODE&gt; &lt;CODE&gt;[^\d]&lt;/CODE&gt;: You could simply use &lt;CODE&gt;\V&lt;/CODE&gt; &lt;CODE&gt;\S&lt;/CODE&gt; &lt;CODE&gt;\D&lt;/CODE&gt; instead, or write actual specific regexes to match what is expected.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 09:05:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435779#M124236</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-06-20T09:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435780#M124237</link>
      <description>&lt;P&gt;Yes I agree with &lt;CODE&gt;[^(on)]&lt;/CODE&gt; that it will match &lt;CODE&gt;(&lt;/CODE&gt; OR &lt;CODE&gt;)&lt;/CODE&gt; but in this example it is not present.&lt;/P&gt;

&lt;P&gt;Regarding &lt;CODE&gt;[^\.]&lt;/CODE&gt; if we provide backslash, will there be any drawback ? &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;[^\v]&lt;/CODE&gt; &lt;CODE&gt;[^\s]&lt;/CODE&gt; &lt;CODE&gt;[^\d]&lt;/CODE&gt; can you please explain benefit to use &lt;CODE&gt;\V&lt;/CODE&gt; &lt;CODE&gt;\S&lt;/CODE&gt; &lt;CODE&gt;\D&lt;/CODE&gt; because both are doing same work.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 09:12:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435780#M124237</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-20T09:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435781#M124238</link>
      <description>&lt;P&gt;No specific drawback of benefit. Just easier to read, but that is perhaps also personal preference &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 09:32:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435781#M124238</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-06-20T09:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435782#M124239</link>
      <description>&lt;P&gt;Thanks for all the info provided, always learning something new. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 09:33:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435782#M124239</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-20T09:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435783#M124240</link>
      <description>&lt;P&gt;Thanks for your answer @FrankVI&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 11:46:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435783#M124240</guid>
      <dc:creator>dhirendra761</dc:creator>
      <dc:date>2019-06-20T11:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex field extraction for the last occurence for a specific text?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435784#M124241</link>
      <description>&lt;P&gt;Thanks for your answer @harsmarvania57 &lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 11:46:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-field-extraction-for-the-last-occurence/m-p/435784#M124241</guid>
      <dc:creator>dhirendra761</dc:creator>
      <dc:date>2019-06-20T11:46:24Z</dc:date>
    </item>
  </channel>
</rss>

