<?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 match the last occurance of the regex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386032#M112679</link>
    <description>&lt;P&gt;Hi Frank,&lt;/P&gt;

&lt;P&gt;Exactly, those multiple occurrences belong to one event. In my case, 1 event is actually one xml log file. And that's why per event, I only want to count the last occurrence of the string and then move on to next event.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 09 Aug 2018 02:35:42 GMT</pubDate>
    <dc:creator>mmdacutanan</dc:creator>
    <dc:date>2018-08-09T02:35:42Z</dc:date>
    <item>
      <title>How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386024#M112671</link>
      <description>&lt;P&gt;I have got a splunk query that searches for the string 'PS1234_IVR_DM' and once found, perform a rex on the field called 'value'.  My problem is that in a single log file (xml format), PS1234_IVR_DM can appear more than once which means I can get more than one possible value for the field 'value'.  In my query below, I do use max_match=0 which captures all occurrences of the string. But then when I remove it, it only gives my the first occurrence of the string. I am only interested in counting the last occurrence. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc sourcetype=xml_logs applicationName=IVR PS1234_IVR_DM | rex "id=\"PS1234_IVR_DM.*?value=\"(?.*?)\"" max_match=0| timechart span=1h dc(corID) by input usenull=f
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can anybody suggest a way to do this, please?&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:44:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386024#M112671</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2020-09-29T20:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386025#M112672</link>
      <description>&lt;P&gt;Apologies, when I copy pasted my splunk query initially, it looks different so I re-posted it again below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc sourcetype=xml_logs applicationName=IVR PS1234_IVR_DM | rex "id=\"PS1234_IVR_DM.*?value=\"(?&amp;lt;input&amp;gt;.*?)\"" max_match=0| timechart span=1h dc(corID) by input usenull=f
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 01:03:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386025#M112672</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2018-08-07T01:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386026#M112673</link>
      <description>&lt;P&gt;Hi mmdacutanan,&lt;/P&gt;

&lt;P&gt;sample events would be helpful, but basically you can use the very expensive negative lookahead regex to get the last occurrence of &lt;CODE&gt;PS1234_IVR_DM&lt;/CODE&gt; like this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(\bPS1234_IVR_DM\b)(?!.+\b(?&amp;lt;input&amp;gt;\1)\b)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above is the regex you can use. &lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 01:10:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386026#M112673</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2018-08-07T01:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386027#M112674</link>
      <description>&lt;P&gt;Here are snippet of the xml log file. You will see there are 2 lines (one near the top, the other near the bottom) that contains PS1234_IVR_DM. The first line has 'value="spanish"'. And then the second occurrence of PS1234_IVR_DM has 'value="nomatch"'. I only want to count the value the last one which is "nomatch".&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dialog duration="13.868" error="0" id="PS1234_IVR_DM" index="25" language="en-US" noinput="0" nomatch="0" speaker="0" startTime="5.944" status="ok" value="spanish"&amp;gt;
  &amp;lt;DialogTurns&amp;gt;
    &amp;lt;turn confidence="0.430000" duration="13.868" inputmode="voice" startTime="5.944" turnindex="1" value="spanish"&amp;gt;
      &amp;lt;details&amp;gt;({interpretation:{GLOBAL:"spanish", delta:"-400"}, interpretation$:[1], utterance:"espanol", inputmode:"voice", confidence:0.4300000071525574, slotconf:{GLOBAL:0.4300000071525574, delta:0.4300000071525574}, marktime:undefined, markname:undefined})&amp;lt;/details&amp;gt;
      &amp;lt;prompts&amp;gt;
        &amp;lt;prompt name="http://10.123.456.789:8080//Postpaid_AudioData/VS_APPL/en-US/0/PS1234_I_02.wav" type="audio"/&amp;gt;
      &amp;lt;/prompts&amp;gt;
      &amp;lt;grammars&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Disambig_Instructions/vxml/grammars/en-US/PS1234_DM.grxml"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/dtmf_global.jsp?keys=7,repeat"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/en-US/universals.grxml#repeat"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/en-US/universals.grxml#spanish"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/choice_digits.jsp?keys=1&amp;amp;amp;items=selfserve"/&amp;gt;
      &amp;lt;/grammars&amp;gt;
    &amp;lt;/turn&amp;gt;
    &amp;lt;turn confidence="0.420000" duration="0.000" inputmode="voice" startTime="19.812" turnindex="2" type="confirm" value="yes"&amp;gt;
      &amp;lt;details&amp;gt;({confidence:0.41999998688697815, utterance:"yeah", inputmode:"voice", interpretation:{CHOICE:"yes"}, interpretation$:[1], recording:undefined, recordingduration:undefined, recordingsize:undefined, marktime:undefined, markname:undefined})&amp;lt;/details&amp;gt;
      &amp;lt;prompts&amp;gt;
        &amp;lt;prompt name="http://10.123.456.789:8080//Postpaid_AudioData/VS_APPL/en-US/0/PS4567.wav" type="audio"/&amp;gt;
        &amp;lt;prompt name="http://10.123.456.789:8080//Postpaid_AudioData/VS_APPL/en-US/0/010.wav" type="audio"/&amp;gt;
      &amp;lt;/prompts&amp;gt;
      &amp;lt;grammars&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/en-US/confirm.grxml"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/confirmDtmf.grxml"/&amp;gt;
      &amp;lt;/grammars&amp;gt;
    &amp;lt;/turn&amp;gt;
  &amp;lt;/DialogTurns&amp;gt;
&amp;lt;/dialog&amp;gt;
&amp;lt;prompt id="PS1234_ExitPrompts_PP" index="26" language="es-US" speaker="0" startTime="2018-08-06 16:59:09.623"&amp;gt;
  &amp;lt;prompts&amp;gt;
    &amp;lt;prompt name="PS1234_E_05" type="audio"/&amp;gt;
  &amp;lt;/prompts&amp;gt;
&amp;lt;/prompt&amp;gt;
&amp;lt;dialog duration="5.148" error="0" id="PS1234_IVR_DM" index="27" language="es-US" noinput="0" nomatch="1" speaker="0" startTime="19.828" status="nomatch" value="nomatch"&amp;gt;
  &amp;lt;DialogTurns&amp;gt;
    &amp;lt;turn duration="5.148" startTime="19.828" turnindex="1" value="nomatch"&amp;gt;
      &amp;lt;prompts&amp;gt;
        &amp;lt;prompt name="http://10.123.456.789:8080//Postpaid_AudioData/VS_APPL/es-US/0/PS1234_I_02.wav" type="audio"/&amp;gt;
        &amp;lt;prompt name="http://10.123.456.789:8080//Postpaid_AudioData/VS_APPL/es-US/0/0.wav" type="audio"/&amp;gt;
      &amp;lt;/prompts&amp;gt;
      &amp;lt;grammars&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Disambig_Instructions/vxml/grammars/es-US/PS1234_DM.grxml"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/dtmf_global.jsp?keys=7,repeat"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/es-US/universals.grxml#repeat"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/es-US/universals.grxml#english"/&amp;gt;
        &amp;lt;grammar name="http://10.123.456.789:8080/Postpaid_CommonData/vxml/grammars/choice_digits.jsp?keys=1&amp;amp;amp;items=selfserve"/&amp;gt;
      &amp;lt;/grammars&amp;gt;
    &amp;lt;/turn&amp;gt;
  &amp;lt;/DialogTurns&amp;gt;
&amp;lt;/dialog&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:44:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386027#M112674</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2020-09-29T20:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386028#M112675</link>
      <description>&lt;P&gt;Okay, that's a different requirement now ... is it:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;you want the last occurrence of a string?&lt;/LI&gt;
&lt;LI&gt;you want the last occurrence of a string followed by &lt;CODE&gt;value="nomatch"&lt;/CODE&gt;?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 07 Aug 2018 01:31:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386028#M112675</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2018-08-07T01:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386029#M112676</link>
      <description>&lt;P&gt;Hello again MuS,&lt;/P&gt;

&lt;P&gt;The string PS1234_IVR_DM will always be followed by a field  called 'value' (which I am renaming as 'input' in my rex expression). The actual value for the 'value' field doesn't matter. What matters is that I am only counting the by the value of the field 'value' where the string PS1234_IVR_DM is last seen.   Hope that helps?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:44:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386029#M112676</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2020-09-29T20:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386030#M112677</link>
      <description>&lt;P&gt;Hey@mmdacutanan,&lt;/P&gt;

&lt;P&gt;You can try something like dis:&lt;BR /&gt;
index=abc sourcetype=xml_logs applicationName=IVR PS1234_IVR_DM|rex "id=\"PS1234_IVR_DM.&lt;EM&gt;?value=\"(?.&lt;/EM&gt;?)\"" max_match=0| eval test=mvindex(input,-1) | timechart span=1h dc(corID) by test usenull=f&lt;/P&gt;

&lt;P&gt;Let me know if this helps!!!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:48:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386030#M112677</guid>
      <dc:creator>deepashri_123</dc:creator>
      <dc:date>2020-09-29T20:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386031#M112678</link>
      <description>&lt;P&gt;Not sure about the structure of your data, but shouldn't each ... section be a separate event in Splunk? Or do these multiple occurences of  really belong together in 1 event for some reason?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 08:36:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386031#M112678</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-08-07T08:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to match the last occurance of the regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386032#M112679</link>
      <description>&lt;P&gt;Hi Frank,&lt;/P&gt;

&lt;P&gt;Exactly, those multiple occurrences belong to one event. In my case, 1 event is actually one xml log file. And that's why per event, I only want to count the last occurrence of the string and then move on to next event.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 02:35:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-the-last-occurance-of-the-regex/m-p/386032#M112679</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2018-08-09T02:35:42Z</dc:date>
    </item>
  </channel>
</rss>

