<?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: Search on XML Multiple Key Attribute Pairs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100171#M25898</link>
    <description>&lt;P&gt;You don't need to match the whole tag - just match everything up to the start of the next one. Also, be careful of your slashes - in your example you have &lt;CODE&gt;&amp;lt;\entry&amp;gt;&lt;/CODE&gt; instead of &lt;CODE&gt;&amp;lt;/entry&amp;gt;&lt;/CODE&gt;, and remember to escape the quotes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex max_match=50 field=abc "(?ms)\&amp;lt;entry key=\"\w+\"\&amp;gt;(?&amp;lt;value&amp;gt;[^\&amp;lt;]+)"
| eval valuelist=mvjoin(value, ", ")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;B&gt;Here's how the regex will be processed&lt;/B&gt;:
&lt;LI&gt;Look for the exact leading text &lt;CODE&gt;&amp;lt;entry key="&lt;/CODE&gt;
&lt;/LI&gt;&lt;LI&gt;Movepast one or more  "word" characters, indicated by &lt;CODE&gt;\w&lt;/CODE&gt;
&lt;/LI&gt;&lt;LI&gt;Move past a quotation mark and a close-bracket
&lt;/LI&gt;&lt;LI&gt;Fill the named capture group "value" with one or more characters that are not an open-bracket symbol&lt;/LI&gt;&lt;/P&gt;

&lt;P&gt;&lt;I&gt;That's it - you're done! The only reason to keep matching would be if you either had multiple similar formats, or if you needed to capture more fields.&lt;/I&gt;&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Here's what the Splunk commands are doing:&lt;/B&gt;
&lt;LI&gt;&lt;CODE&gt;rex&lt;/CODE&gt; will repeat the regex processing up to 50 times until all matches are found. Put each match of the named capture group &lt;CODE&gt;value&lt;/CODE&gt; into a field named &lt;CODE&gt;value&lt;/CODE&gt;.
&lt;/LI&gt;&lt;LI&gt;&lt;CODE&gt;eval&lt;/CODE&gt; will then join all of these matches into a single line of text, putting a comma and a space between each match.&lt;/LI&gt;&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Learning Regular Expressions&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;Get a good regex tester like &lt;A href="http://kodos.sourceforge.net/" rel="nofollow"&gt;Kodos&lt;/A&gt; or &lt;A href="http://www.regexbuddy.com/" rel="nofollow"&gt;RegexBuddy&lt;/A&gt;, and take a good look at &lt;A href="http://http://www.regular-expressions.info/" rel="nofollow"&gt;regular-expressions.info&lt;/A&gt; if you need to practice. That's usually easier than trying to debug regexes in the Splunk command line. Also, try to work out exactly what's going on in each of the other examples people have posted -- getting a handle the examples is the key to being able to being able to adapt them to your own needs more quickly.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Dec 2010 06:38:33 GMT</pubDate>
    <dc:creator>southeringtonp</dc:creator>
    <dc:date>2010-12-07T06:38:33Z</dc:date>
    <item>
      <title>Search on XML Multiple Key Attribute Pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100170#M25897</link>
      <description>&lt;P&gt;I am stranded extracting "values"  from below xml &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   &amp;lt;SearchElements&amp;gt;
    &amp;lt;entry key="FirstName"&amp;gt;%&amp;lt;/entry&amp;gt;
    &amp;lt;entry key="Gender"&amp;gt;MALE&amp;lt;/entry&amp;gt;
    &amp;lt;entry key="State"&amp;gt;VA&amp;lt;/entry&amp;gt;   
&amp;lt;/SearchElements&amp;gt; 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am expecting regex to give me output of values as: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;%, MALE, VA 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is the regex which doesnt work as expected. Please let me know whats going wrong&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=abc "(?ms)\&amp;lt;entry key="\w+"\&amp;gt;(?P&amp;lt;abc&amp;gt;[^&amp;lt;]+)&amp;lt;\entry&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Dec 2010 05:53:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100170#M25897</guid>
      <dc:creator>bansi</dc:creator>
      <dc:date>2010-12-07T05:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Search on XML Multiple Key Attribute Pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100171#M25898</link>
      <description>&lt;P&gt;You don't need to match the whole tag - just match everything up to the start of the next one. Also, be careful of your slashes - in your example you have &lt;CODE&gt;&amp;lt;\entry&amp;gt;&lt;/CODE&gt; instead of &lt;CODE&gt;&amp;lt;/entry&amp;gt;&lt;/CODE&gt;, and remember to escape the quotes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex max_match=50 field=abc "(?ms)\&amp;lt;entry key=\"\w+\"\&amp;gt;(?&amp;lt;value&amp;gt;[^\&amp;lt;]+)"
| eval valuelist=mvjoin(value, ", ")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;B&gt;Here's how the regex will be processed&lt;/B&gt;:
&lt;LI&gt;Look for the exact leading text &lt;CODE&gt;&amp;lt;entry key="&lt;/CODE&gt;
&lt;/LI&gt;&lt;LI&gt;Movepast one or more  "word" characters, indicated by &lt;CODE&gt;\w&lt;/CODE&gt;
&lt;/LI&gt;&lt;LI&gt;Move past a quotation mark and a close-bracket
&lt;/LI&gt;&lt;LI&gt;Fill the named capture group "value" with one or more characters that are not an open-bracket symbol&lt;/LI&gt;&lt;/P&gt;

&lt;P&gt;&lt;I&gt;That's it - you're done! The only reason to keep matching would be if you either had multiple similar formats, or if you needed to capture more fields.&lt;/I&gt;&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Here's what the Splunk commands are doing:&lt;/B&gt;
&lt;LI&gt;&lt;CODE&gt;rex&lt;/CODE&gt; will repeat the regex processing up to 50 times until all matches are found. Put each match of the named capture group &lt;CODE&gt;value&lt;/CODE&gt; into a field named &lt;CODE&gt;value&lt;/CODE&gt;.
&lt;/LI&gt;&lt;LI&gt;&lt;CODE&gt;eval&lt;/CODE&gt; will then join all of these matches into a single line of text, putting a comma and a space between each match.&lt;/LI&gt;&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Learning Regular Expressions&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;Get a good regex tester like &lt;A href="http://kodos.sourceforge.net/" rel="nofollow"&gt;Kodos&lt;/A&gt; or &lt;A href="http://www.regexbuddy.com/" rel="nofollow"&gt;RegexBuddy&lt;/A&gt;, and take a good look at &lt;A href="http://http://www.regular-expressions.info/" rel="nofollow"&gt;regular-expressions.info&lt;/A&gt; if you need to practice. That's usually easier than trying to debug regexes in the Splunk command line. Also, try to work out exactly what's going on in each of the other examples people have posted -- getting a handle the examples is the key to being able to being able to adapt them to your own needs more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2010 06:38:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100171#M25898</guid>
      <dc:creator>southeringtonp</dc:creator>
      <dc:date>2010-12-07T06:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Search on XML Multiple Key Attribute Pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100172#M25899</link>
      <description>&lt;P&gt;Thanks for wonderful explaination. Thats really informative&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2010 03:41:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100172#M25899</guid>
      <dc:creator>bansi</dc:creator>
      <dc:date>2010-12-08T03:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Search on XML Multiple Key Attribute Pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100173#M25900</link>
      <description>&lt;P&gt;Please take a moment to answer the posting on&lt;/P&gt;

&lt;P&gt;&lt;A href="http://answers.splunk.com/questions/9657/search-between-two-files-with-output-of-one-file-i-e-list-of-ids-passed-as-inp"&gt;http://answers.splunk.com/questions/9657/search-between-two-files-with-output-of-one-file-i-e-list-of-ids-passed-as-inp&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2010 05:05:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-on-XML-Multiple-Key-Attribute-Pairs/m-p/100173#M25900</guid>
      <dc:creator>bansi</dc:creator>
      <dc:date>2010-12-08T05:05:28Z</dc:date>
    </item>
  </channel>
</rss>

