<?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 edit my regex to capture the Nth match in an XML file? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regex-to-capture-the-Nth-match-in-an-XML-file/m-p/229825#M68090</link>
    <description>&lt;P&gt;Will something like this work for you (run anywhere sample)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="&amp;lt;Name&amp;gt;eth0&amp;lt;/Name&amp;gt; &amp;lt;IP&amp;gt;192.168.1.1/24&amp;lt;/IP&amp;gt; &amp;lt;MACAddress&amp;gt;xx:xx:xx:xx:xx:x&amp;lt;/MACAddress&amp;gt; &amp;lt;Status&amp;gt;ok&amp;lt;/Status&amp;gt; &amp;lt;Name&amp;gt;eth1&amp;lt;/Name&amp;gt; &amp;lt;IP&amp;gt;192.168.1.2/24&amp;lt;/IP&amp;gt; &amp;lt;MACAddress&amp;gt;xx:xx:xx:xx:xx:x&amp;lt;/MACAddress&amp;gt; &amp;lt;Status&amp;gt;ok&amp;lt;/Status&amp;gt; &amp;lt;Name&amp;gt;eth3&amp;lt;/Name&amp;gt; &amp;lt;IP&amp;gt;192.168.1.2/24&amp;lt;/IP&amp;gt; &amp;lt;MACAddress&amp;gt;xx:xx:xx:xx:xx:x&amp;lt;/MACAddress&amp;gt; &amp;lt;Status&amp;gt;ok&amp;lt;/Status&amp;gt;" | table _raw 
| rex max_match=0 "(\&amp;lt;Name\&amp;gt;(?&amp;lt;Ethernet&amp;gt;[^\&amp;lt;]+)\&amp;lt;\/Name\&amp;gt;)" | eval instance1=mvindex(Ethernet,0) | eval instance2=mvindex(Ethernet,1) | eval instance3=mvindex(Ethernet,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 May 2016 15:44:24 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-05-03T15:44:24Z</dc:date>
    <item>
      <title>How to edit my regex to capture the Nth match in an XML file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regex-to-capture-the-Nth-match-in-an-XML-file/m-p/229824#M68089</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I am struggling while trying to write a regex to capture the second and third occurrence of a pattern. &lt;/P&gt;

&lt;P&gt;Here is my example:&lt;BR /&gt;
The Following XML file for instance:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Name&amp;gt;eth0&amp;lt;/Name&amp;gt;
&amp;lt;IP&amp;gt;192.168.1.1/24&amp;lt;/IP&amp;gt;
 &amp;lt;MACAddress&amp;gt;xx:xx:xx:xx:xx:x&amp;lt;/MACAddress&amp;gt;
 &amp;lt;Status&amp;gt;ok&amp;lt;/Status&amp;gt; 
&amp;lt;Name&amp;gt;eth1&amp;lt;/Name&amp;gt;
 &amp;lt;IP&amp;gt;192.168.1.2/24&amp;lt;/IP&amp;gt; 
&amp;lt;MACAddress&amp;gt;xx:xx:xx:xx:xx:x&amp;lt;/MACAddress&amp;gt;
 &amp;lt;Status&amp;gt;ok&amp;lt;/Status&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I manage to catch the first &lt;CODE&gt;eth0&lt;/CODE&gt; by doing: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;(Name)&amp;gt;(?&amp;lt;eth0name&amp;gt;\D+\d+)&amp;lt;/(\1)&amp;gt;\n
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I can't manage to catch the &lt;CODE&gt;eth1&lt;/CODE&gt; field...&lt;BR /&gt;
Sorry if this is a dumb question... I am new to Regex...&lt;BR /&gt;
I am using &lt;A href="https://regex101.com/"&gt;https://regex101.com/&lt;/A&gt; to help me out, but I'm stuck..&lt;/P&gt;

&lt;P&gt;Can someone help me on this one please?&lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2016 15:04:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regex-to-capture-the-Nth-match-in-an-XML-file/m-p/229824#M68089</guid>
      <dc:creator>Estrellia</dc:creator>
      <dc:date>2016-05-03T15:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my regex to capture the Nth match in an XML file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regex-to-capture-the-Nth-match-in-an-XML-file/m-p/229825#M68090</link>
      <description>&lt;P&gt;Will something like this work for you (run anywhere sample)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="&amp;lt;Name&amp;gt;eth0&amp;lt;/Name&amp;gt; &amp;lt;IP&amp;gt;192.168.1.1/24&amp;lt;/IP&amp;gt; &amp;lt;MACAddress&amp;gt;xx:xx:xx:xx:xx:x&amp;lt;/MACAddress&amp;gt; &amp;lt;Status&amp;gt;ok&amp;lt;/Status&amp;gt; &amp;lt;Name&amp;gt;eth1&amp;lt;/Name&amp;gt; &amp;lt;IP&amp;gt;192.168.1.2/24&amp;lt;/IP&amp;gt; &amp;lt;MACAddress&amp;gt;xx:xx:xx:xx:xx:x&amp;lt;/MACAddress&amp;gt; &amp;lt;Status&amp;gt;ok&amp;lt;/Status&amp;gt; &amp;lt;Name&amp;gt;eth3&amp;lt;/Name&amp;gt; &amp;lt;IP&amp;gt;192.168.1.2/24&amp;lt;/IP&amp;gt; &amp;lt;MACAddress&amp;gt;xx:xx:xx:xx:xx:x&amp;lt;/MACAddress&amp;gt; &amp;lt;Status&amp;gt;ok&amp;lt;/Status&amp;gt;" | table _raw 
| rex max_match=0 "(\&amp;lt;Name\&amp;gt;(?&amp;lt;Ethernet&amp;gt;[^\&amp;lt;]+)\&amp;lt;\/Name\&amp;gt;)" | eval instance1=mvindex(Ethernet,0) | eval instance2=mvindex(Ethernet,1) | eval instance3=mvindex(Ethernet,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 May 2016 15:44:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regex-to-capture-the-Nth-match-in-an-XML-file/m-p/229825#M68090</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-05-03T15:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my regex to capture the Nth match in an XML file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regex-to-capture-the-Nth-match-in-an-XML-file/m-p/229826#M68091</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;Thank you for your help, this is indeed a way to achieve what I wanted to do.&lt;/P&gt;

&lt;P&gt;I clearly didn't think of that.. thanks!&lt;/P&gt;

&lt;P&gt;Have a nice day.&lt;/P&gt;

&lt;P&gt;Ps: If anyone also think of a 100% pure regex way to do that I also am interested for learning purposes.&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2016 15:56:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regex-to-capture-the-Nth-match-in-an-XML-file/m-p/229826#M68091</guid>
      <dc:creator>Estrellia</dc:creator>
      <dc:date>2016-05-03T15:56:36Z</dc:date>
    </item>
  </channel>
</rss>

