<?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: Regular Expression to extract third string when there are multiple tags with same name in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402992#M116597</link>
    <description>&lt;P&gt;This regex should do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?s)(?:&amp;lt;Val&amp;gt;[^&amp;lt;]*&amp;lt;\/Val&amp;gt;[^&amp;lt;]*){2}&amp;lt;Val&amp;gt;(?&amp;lt;field&amp;gt;\w*)&amp;lt;.*$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Feb 2019 13:37:03 GMT</pubDate>
    <dc:creator>FritzWittwer_ol</dc:creator>
    <dc:date>2019-02-20T13:37:03Z</dc:date>
    <item>
      <title>Regular Expression to extract third string when there are multiple tags with same name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402991#M116596</link>
      <description>&lt;P&gt;Hi ,&lt;BR /&gt;
 I need some help with regular expression.&lt;/P&gt;

&lt;P&gt;I have a field call "f" which is having XML message. &lt;BR /&gt;
I want to extract one of the value from a XML Tag .&lt;/P&gt;

&lt;P&gt;The tricky part is , each XML has multiple  "Val" tags with different content init.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt; : lets say field "f" consists of below values along with some other XML tags. I only want to get "SE" as an output using regular expression.&lt;/P&gt;

&lt;P&gt;"SE" will remain in third place in  tag.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Val&amp;gt;123&amp;lt;/Val&amp;gt;
&amp;lt;Val&amp;gt;ABC&amp;lt;/Val&amp;gt;
&amp;lt;Val&amp;gt;SE&amp;lt;/Val&amp;gt;
&amp;lt;Val&amp;gt;Information&amp;lt;/Val&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried below regular expressions. But they havent meet my criteria to get only the value which is present in third  tag.&lt;/P&gt;

&lt;P&gt;search | rex field=f "\"(?\w*)&amp;lt;\/Val&amp;gt;""&lt;/P&gt;

&lt;P&gt;Above regular expression gives only 123 as an output&lt;/P&gt;

&lt;P&gt;search | rex field=f "\"(?\w*)&amp;lt;\/Val&amp;gt;"" max_match=0&lt;/P&gt;

&lt;P&gt;Above regular expression gives below output&lt;BR /&gt;
123&lt;BR /&gt;
ABC&lt;BR /&gt;
SE&lt;BR /&gt;
Information&lt;/P&gt;

&lt;P&gt;Need your help to get SE as an output using regular expression.&lt;/P&gt;

&lt;P&gt;Thanks for your help in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 09:39:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402991#M116596</guid>
      <dc:creator>kirangurram</dc:creator>
      <dc:date>2019-02-20T09:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression to extract third string when there are multiple tags with same name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402992#M116597</link>
      <description>&lt;P&gt;This regex should do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?s)(?:&amp;lt;Val&amp;gt;[^&amp;lt;]*&amp;lt;\/Val&amp;gt;[^&amp;lt;]*){2}&amp;lt;Val&amp;gt;(?&amp;lt;field&amp;gt;\w*)&amp;lt;.*$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Feb 2019 13:37:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402992#M116597</guid>
      <dc:creator>FritzWittwer_ol</dc:creator>
      <dc:date>2019-02-20T13:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression to extract third string when there are multiple tags with same name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402993#M116598</link>
      <description>&lt;P&gt;What about not using regex at all and use xpath?&lt;/P&gt;

&lt;P&gt;| makeresults &lt;BR /&gt;
| eval raw="123&lt;BR /&gt;
 ABC&lt;BR /&gt;
 SE&lt;BR /&gt;
 Information"&lt;BR /&gt;
| rename raw AS _raw&lt;BR /&gt;
| xpath "/Val[3]" outfield=blah&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 14:42:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402993#M116598</guid>
      <dc:creator>jason_prondak</dc:creator>
      <dc:date>2019-02-20T14:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression to extract third string when there are multiple tags with same name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402994#M116599</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval _raw="&amp;lt;Val&amp;gt;123&amp;lt;/Val&amp;gt;
&amp;lt;Val&amp;gt;ABC&amp;lt;/Val&amp;gt;
&amp;lt;Val&amp;gt;SE&amp;lt;/Val&amp;gt;
&amp;lt;Val&amp;gt;Information&amp;lt;/Val&amp;gt;"

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution."

| rex max_match=3 "(?ms)&amp;lt;Val&amp;gt;(?&amp;lt;Val&amp;gt;.*?)&amp;lt;/Val&amp;gt;"
| eval Val=mvindex(Val, 2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Feb 2019 05:51:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402994#M116599</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-21T05:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression to extract third string when there are multiple tags with same name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402995#M116600</link>
      <description>&lt;P&gt;thanks for your reply @FritzWittwer. I didnt get desired output with the above regex. I am just getting blank output.&lt;/P&gt;

&lt;P&gt;let me provide entire field f content to bring better clarity.&lt;/P&gt;

&lt;P&gt;field f is having below XML content. I just want to count stats using country code which is present in &lt;CODE&gt;&amp;lt;Val&amp;gt;FR&amp;lt;/Val&amp;gt;&lt;/CODE&gt; tag.&lt;/P&gt;

&lt;P&gt;when I used below query , I am getting below output.&lt;BR /&gt;
    index="sample" search&lt;BR /&gt;
    | rex field=f "&amp;lt;Val&amp;gt;"(?&lt;COUNTRY&gt;\w*)&amp;lt;\/Val&amp;gt;"" max_match=0&lt;BR /&gt;
    | table country&lt;/COUNTRY&gt;&lt;/P&gt;

&lt;P&gt;output : &lt;BR /&gt;
URO&lt;BR /&gt;
LEH&lt;BR /&gt;
FR&lt;BR /&gt;
Information&lt;/P&gt;

&lt;P&gt;My desired output : &lt;BR /&gt;
FR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;f: &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&amp;lt;ns23:EvtMsg xmlns:ns23="http://www.dhl.com/Express/CM/GenericEventMsg/v2" xmlns:ns5="http://www.dhl.com/Express/CM/CM_GenericRequest/v2"&amp;gt;&amp;lt;Hdr Id="22de623e-b8ab-4def-b28a-7be0f5b76bd0" Ver="1.038" Dtm="2019-02-21T05:59:46" CorrId="fc6fd801-ad67-47b3-ac0b-adeb0a6e5ed0"&amp;gt;&amp;lt;GI SrcAppCd="ABC"&amp;gt;&amp;lt;TID Src="E2E" TID="f4a82e5b-9f55-4d96-b8b0-1c1caab398d1"/&amp;gt;&amp;lt;/GI&amp;gt;&amp;lt;Sndr AppCd="ABC" AppVer="2.000" AppNm="ABC"/&amp;gt;&amp;lt;Rcp AppCd="ABC" AppNm="ABC"&amp;gt;&amp;lt;GId Id="fc6fd801-ad67-47b3-ac0b-adeb0a6e5ed0" IdTp="RQMSGID"/&amp;gt;&amp;lt;/Rcp&amp;gt;&amp;lt;Rcp AppCd="ABC" AppNm="ABC"/&amp;gt;&amp;lt;/Hdr&amp;gt;&amp;lt;Bd&amp;gt;&amp;lt;BOEvt&amp;gt;&amp;lt;GI CorrId="697b8f2d-163b-43ed-a87b-1a657d2d5428"/&amp;gt;&amp;lt;ShpId OrgCCd="US"&amp;gt;1234567891&amp;lt;/ShpId&amp;gt;&amp;lt;Evt&amp;gt;&amp;lt;TyCd&amp;gt;ABCAB&amp;lt;/TyCd&amp;gt;&amp;lt;Dtm Off="+01:00"&amp;gt;2019-02-21T05:59:46&amp;lt;/Dtm&amp;gt;&amp;lt;RecDtm Off="+01:00"&amp;gt;2019-02-21T05:59:46&amp;lt;/RecDtm&amp;gt;&amp;lt;SDtm Off="+01:00"&amp;gt;2019-02-21T05:59:46&amp;lt;/SDtm&amp;gt;&amp;lt;RCd&amp;gt;ABCAB&amp;lt;/RCd&amp;gt;&amp;lt;RDsc&amp;gt;Receiver Time Window&amp;lt;/RDsc&amp;gt;&amp;lt;Rmk/&amp;gt;&amp;lt;COpsFncId&amp;gt;&amp;lt;OpsFncTyCd&amp;gt;HAL&amp;lt;/OpsFncTyCd&amp;gt;&amp;lt;OpsFncId&amp;gt;LEHURO&amp;lt;/OpsFncId&amp;gt;&amp;lt;OpsFncIdAddDtEl&amp;gt;&amp;lt;Cd&amp;gt;FcCd&amp;lt;/Cd&amp;gt;&amp;lt;Val&amp;gt;URO&amp;lt;/Val&amp;gt;&amp;lt;/OpsFncIdAddDtEl&amp;gt;&amp;lt;OpsFncIdAddDtEl&amp;gt;&amp;lt;Cd&amp;gt;SrvaCd&amp;lt;/Cd&amp;gt;&amp;lt;Val&amp;gt;LEH&amp;lt;/Val&amp;gt;&amp;lt;/OpsFncIdAddDtEl&amp;gt;&amp;lt;OpsFncIdAddDtEl&amp;gt;&amp;lt;Cd&amp;gt;CtryCd&amp;lt;/Cd&amp;gt;**&amp;lt;Val&amp;gt;FR&amp;lt;/Val&amp;gt;**&amp;lt;/OpsFncIdAddDtEl&amp;gt;&amp;lt;/COpsFncId&amp;gt;&amp;lt;CIndvId&amp;gt;ABC&amp;lt;/CIndvId&amp;gt;&amp;lt;DatElGrp Cd="RcvDlvStrDtm"&amp;gt;&amp;lt;DatEl&amp;gt;&amp;lt;Cd&amp;gt;Dtm&amp;lt;/Cd&amp;gt;&amp;lt;Val Ty="DATETIME"&amp;gt;2019-02-21T23:00:00Z&amp;lt;/Val&amp;gt;&amp;lt;/DatEl&amp;gt;&amp;lt;DatEl&amp;gt;&amp;lt;Cd&amp;gt;TmOff&amp;lt;/Cd&amp;gt;&amp;lt;Val Ty="CHAR"&amp;gt;+01:00&amp;lt;/Val&amp;gt;&amp;lt;/DatEl&amp;gt;&amp;lt;/DatElGrp&amp;gt;&amp;lt;DatElGrp Cd="RcvDlvEndDtm"&amp;gt;&amp;lt;DatEl&amp;gt;&amp;lt;Cd&amp;gt;Dtm&amp;lt;/Cd&amp;gt;&amp;lt;Val Ty="DATETIME"&amp;gt;2019-02-22T22:59:00Z&amp;lt;/Val&amp;gt;&amp;lt;/DatEl&amp;gt;&amp;lt;DatEl&amp;gt;&amp;lt;Cd&amp;gt;TmOff&amp;lt;/Cd&amp;gt;&amp;lt;Val Ty="CHAR"&amp;gt;+01:00&amp;lt;/Val&amp;gt;&amp;lt;/DatEl&amp;gt;&amp;lt;/DatElGrp&amp;gt;&amp;lt;DatElGrp Cd="CfgDat"&amp;gt;&amp;lt;DatEl&amp;gt;&amp;lt;Cd&amp;gt;Cat&amp;lt;/Cd&amp;gt;&amp;lt;Val&amp;gt;Information&amp;lt;/Val&amp;gt;&amp;lt;/DatEl&amp;gt;&amp;lt;/DatElGrp&amp;gt;&amp;lt;GI CorrId="573a6e52-c795-4066-9091-58d5281edd4e"/&amp;gt;&amp;lt;/Evt&amp;gt;&amp;lt;/BOEvt&amp;gt;&amp;lt;/Bd&amp;gt;&amp;lt;/ns23:EvtMsg&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Feb 2019 07:17:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402995#M116600</guid>
      <dc:creator>kirangurram</dc:creator>
      <dc:date>2019-02-21T07:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression to extract third string when there are multiple tags with same name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402996#M116601</link>
      <description>&lt;P&gt;@woodcock , thanks a lot. your solutions works for me.&lt;/P&gt;

&lt;P&gt;I have use below query to get per day stats&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search | rex field=f max_match=3 "(?ms)&amp;lt;Val&amp;gt;(?&amp;lt;Val&amp;gt;.*?)&amp;lt;/Val&amp;gt;"
| eval Val=mvindex(Val, 2)
| search Val=XX
| timechart span=1d count by "n" limit=0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Feb 2019 07:57:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402996#M116601</guid>
      <dc:creator>kirangurram</dc:creator>
      <dc:date>2019-02-21T07:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression to extract third string when there are multiple tags with same name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402997#M116602</link>
      <description>&lt;P&gt;xpath doesnt seems to work @jason.prondak , I am getting incorrect output&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 02:57:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regular-Expression-to-extract-third-string-when-there-are/m-p/402997#M116602</guid>
      <dc:creator>kirangurram</dc:creator>
      <dc:date>2019-03-20T02:57:50Z</dc:date>
    </item>
  </channel>
</rss>

