<?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: Help With Regular Expression To Extract Values Between XML Element Tags on Multi-line in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99996#M25845</link>
    <description>&lt;P&gt;Modified the answer&lt;/P&gt;</description>
    <pubDate>Tue, 07 Dec 2010 02:42:11 GMT</pubDate>
    <dc:creator>ziegfried</dc:creator>
    <dc:date>2010-12-07T02:42:11Z</dc:date>
    <item>
      <title>Help With Regular Expression To Extract Values Between XML Element Tags on Multi-line</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99993#M25842</link>
      <description>&lt;P&gt;How to extract values between Elements tag. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;DataNode node-type="Contract"&amp;gt;
            &amp;lt;TransactionAttributes&amp;gt;
                &amp;lt;entry key="CONTRACT_ID"&amp;gt;contract2_100&amp;lt;/entry&amp;gt;              
            &amp;lt;/TransactionAttributes&amp;gt;
            &amp;lt;Elements&amp;gt;
                &amp;lt;ContractId&amp;gt;true&amp;lt;/ContractId&amp;gt;
                &amp;lt;DateOfBirth&amp;gt;true&amp;lt;/DateOfBirth&amp;gt;
            &amp;lt;/Elements&amp;gt;
        &amp;lt;/DataNode&amp;gt;
&amp;lt;DataNode roster-type="search" node-type="Roster"&amp;gt;
            &amp;lt;TransactionAttributes&amp;gt;
                &amp;lt;entry key="TRAN_ID"&amp;gt;001&amp;lt;/entry&amp;gt;                
            &amp;lt;/TransactionAttributes&amp;gt;
            &amp;lt;Elements&amp;gt;
                &amp;lt;PhoneNo&amp;gt;true&amp;lt;/PhoneNo&amp;gt;
                &amp;lt;SNumber&amp;gt;true&amp;lt;/SNumber&amp;gt;
            &amp;lt;/Elements&amp;gt;
&amp;lt;/DataNode&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The following regular expression erroneously  extract values apart from Element tags 
so Please let me know  how to restrict it to retrieve values only between  tags &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "(?m)\&amp;lt;Elements&amp;gt;(?&amp;lt;abc&amp;gt;.*)&amp;lt;/Elements&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;results in &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;ContractId&amp;gt;true&amp;lt;/ContractId&amp;gt;&amp;lt;Name name-type="Name"&amp;gt;true&amp;lt;/Name&amp;gt;&amp;lt;DateOfBirth&amp;gt;true&amp;lt;/DateOfBirth&amp;gt;&amp;lt;/Elements&amp;gt;&amp;lt;/DataNode&amp;gt;&amp;lt;DataNode &amp;gt;&amp;lt;TransactionAttributes&amp;gt;&amp;lt;entry key="CONTRACT_ID"&amp;gt;123&amp;lt;/entry&amp;gt;&amp;lt;entry 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;whereas the expected results is only between Elements tag i.e.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;ContractId&amp;gt;true&amp;lt;/ContractId&amp;gt;&amp;lt;Name name-type="Name"&amp;gt;true&amp;lt;/Name&amp;gt;&amp;lt;DateOfBirth&amp;gt;true&amp;lt;/DateOfBirth&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Dec 2010 01:10:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99993#M25842</guid>
      <dc:creator>bansi</dc:creator>
      <dc:date>2010-12-07T01:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Help With Regular Expression To Extract Values Between XML Element Tags on Multi-line</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99994#M25843</link>
      <description>&lt;P&gt;The problem is that &lt;CODE&gt;.*&lt;/CODE&gt; matches greedy and so the matched part ends at the last occurrence of "&lt;CODE&gt;&amp;lt;/Elements&amp;gt;&lt;/CODE&gt;". You can make it work by adding the non-greedy quantifier: &lt;CODE&gt;.*?&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So this regex should work as expected:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "(?ms)\&amp;lt;Elements\&amp;gt;(?&amp;lt;abc&amp;gt;.*?)\&amp;lt;/Elements\&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In order to extract all matching parts of the event, you have to add the max_match parameter to the rex command. This instruct Splunk to make the resulting field multi-valued.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "(?ms)\&amp;lt;Elements\&amp;gt;(?&amp;lt;abc&amp;gt;.*?)\&amp;lt;/Elements\&amp;gt;" max_match=999
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Dec 2010 01:43:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99994#M25843</guid>
      <dc:creator>ziegfried</dc:creator>
      <dc:date>2010-12-07T01:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help With Regular Expression To Extract Values Between XML Element Tags on Multi-line</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99995#M25844</link>
      <description>&lt;P&gt;Thank you so much. But it doesn't picks the &lt;ELEMENTS&gt; under different &lt;DATANODE&gt; i.e. PhoneNo, SNumber as shown in xml of my earlier posting.&lt;/DATANODE&gt;&lt;/ELEMENTS&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2010 02:21:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99995#M25844</guid>
      <dc:creator>bansi</dc:creator>
      <dc:date>2010-12-07T02:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help With Regular Expression To Extract Values Between XML Element Tags on Multi-line</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99996#M25845</link>
      <description>&lt;P&gt;Modified the answer&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2010 02:42:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99996#M25845</guid>
      <dc:creator>ziegfried</dc:creator>
      <dc:date>2010-12-07T02:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Help With Regular Expression To Extract Values Between XML Element Tags on Multi-line</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99997#M25846</link>
      <description>&lt;P&gt;Thank you so much once again. I would greatly appreciate if you could point me to good regular expression website specifically the one which helps me in writing fast Splunk queries.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2010 02:56:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99997#M25846</guid>
      <dc:creator>bansi</dc:creator>
      <dc:date>2010-12-07T02:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Help With Regular Expression To Extract Values Between XML Element Tags on Multi-line</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99998#M25847</link>
      <description>&lt;P&gt;Here are a few links that might be helpful: &lt;BR /&gt;
&lt;A href="http://www.regular-expressions.info/"&gt;http://www.regular-expressions.info/&lt;/A&gt; &lt;BR /&gt;
&lt;A href="http://docs.python.org/library/re.html"&gt;http://docs.python.org/library/re.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://gskinner.com/RegExr/"&gt;http://gskinner.com/RegExr/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2010 03:29:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99998#M25847</guid>
      <dc:creator>ziegfried</dc:creator>
      <dc:date>2010-12-07T03:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help With Regular Expression To Extract Values Between XML Element Tags on Multi-line</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99999#M25848</link>
      <description>&lt;P&gt;Thank. I need one more help. I am stranded extracting "values" only  from below xml&lt;/P&gt;

&lt;P&gt;&lt;SEARCHELEMENTS&gt;&lt;BR /&gt;
    &lt;ENTRY key="FirstName"&gt;%&lt;/ENTRY&gt;&lt;BR /&gt;
    &lt;ENTRY key="Gender"&gt;MALE&lt;/ENTRY&gt;&lt;BR /&gt;
    &lt;ENTRY key="State"&gt;VA&lt;/ENTRY&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;/SEARCHELEMENTS&gt;&lt;/P&gt;

&lt;P&gt;I am expecting regex to give me output of values as: %, MALE, VA&lt;/P&gt;

&lt;P&gt;rex "(?ms)&amp;lt;SearchElements&amp;gt;(?&lt;ABC&gt;.&lt;EM&gt;?)&amp;lt;/SearchElements&amp;gt;" max_match=999 |  rex field=abc max_match=50 "&amp;lt;entry key=".&lt;/EM&gt;"&amp;gt;&amp;lt;(?&lt;KEYS&gt;[A-Za-z]+)&lt;/KEYS&gt;"| eval keys=mvjoin(keys,",") |  table abc&lt;/ABC&gt;&lt;/P&gt;

&lt;P&gt;Please take a moment to correct the regex&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:21:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-With-Regular-Expression-To-Extract-Values-Between-XML/m-p/99999#M25848</guid>
      <dc:creator>bansi</dc:creator>
      <dc:date>2020-09-28T09:21:43Z</dc:date>
    </item>
  </channel>
</rss>

