<?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: Clarification on regular expression to extract XML field as multivalue field and related fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203661#M59165</link>
    <description>&lt;P&gt;However still seem to be getting some strange results - will have to investigate further.&lt;BR /&gt;
&lt;STRONG&gt;Edit:&lt;/STRONG&gt; This was an issue with the data - the REGEX expression seems to be OK.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Dec 2016 03:16:32 GMT</pubDate>
    <dc:creator>alexandermunce</dc:creator>
    <dc:date>2016-12-21T03:16:32Z</dc:date>
    <item>
      <title>Clarification on regular expression to extract XML field as multivalue field and related fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203658#M59162</link>
      <description>&lt;P&gt;I am working with a datasource which contains multiple instances of an XML value which exists similarly to this:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;(WITHOUT THE SPACES)&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Sample Event 1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt; ab1:search-name &amp;gt;ABC-123-XYZ &amp;lt; / ab1:ab1:search-name &amp;gt;
&amp;lt; ab1:search-response &amp;gt; YES &amp;lt; / ab1:search-response &amp;gt;
&amp;lt; ab1:search-relevance &amp;gt; 15 &amp;lt; / ab1:search-relevance &amp;gt;
&amp;lt; ab1:analysis / &amp;gt;
&amp;lt; ab1:search-name &amp;gt;ABC-001-PROD  &amp;lt; / ab1:search-name &amp;gt;
&amp;lt; ab1:search-response &amp;gt; NO &amp;lt; / ab1:search-response &amp;gt;
&amp;lt; ab1:search-relevance &amp;gt; 25 &amp;lt; / ab1:search-relevance &amp;gt;
&amp;lt; ab1:analysis / &amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sample Event 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt; ab1:search-name &amp;gt;ABC-123-XYZ &amp;lt; / ab1:search-name &amp;gt;
&amp;lt; ab1:search-response &amp;gt; YES &amp;lt; / ab1:search-response &amp;gt;
&amp;lt; ab1:search-relevance &amp;gt; 10 &amp;lt; / ab1:search-relevance &amp;gt;
&amp;lt; ab1:analysis / &amp;gt;
&amp;lt; ab1:search-name &amp;gt;ABC-001-PROD  &amp;lt; / ab1:search-name &amp;gt;
&amp;lt; ab1:search-response &amp;gt; YES &amp;lt; / ab1:search-response &amp;gt;
&amp;lt; ab1:search-relevance &amp;gt; 20 &amp;lt; / ab1:search-relevance &amp;gt;
&amp;lt; ab1:analysis / &amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am wanting to write a &lt;STRONG&gt;REGEX&lt;/STRONG&gt; expression to use with the &lt;STRONG&gt;rex&lt;/STRONG&gt; command to extract the data contained within the &lt;STRONG&gt;&amp;lt; ab1:search-name &amp;gt; &amp;lt; / ab1:search-name &amp;gt;&lt;/STRONG&gt; tags into a new field named &lt;STRONG&gt;search_name&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;I understand that as there are multiple instances of this field in each event that the new field will have to be a multivalue field (which will require the rex &lt;STRONG&gt;max_match=0&lt;/STRONG&gt; argument).&lt;/P&gt;

&lt;P&gt;Therefore I believe my command should look something similar to the below;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search query | rex [REGEX EXPRESSION] max_match=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have tried various REGEX expressions but am having trouble with the fact the data contains characters and symbols.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;RELATED QUESTION&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;As you can see in the data sample above - each instance of the &amp;lt; ab1:search-name &amp;gt; &amp;lt; / ab1:search-name &amp;gt; tag has related values beneath it (search-response, search-relevance, etc).&lt;/P&gt;

&lt;P&gt;My question is, once the rex command extracts the field, will there be any way to relate the data which fell beneath each instance of the tag to each individual value - or will the correlation be lost? &lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 01:06:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203658#M59162</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-21T01:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Clarification on regular expression to extract XML field as multivalue field and related fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203659#M59163</link>
      <description>&lt;P&gt;Try this "run-anywhere" sample. Use from the first &lt;CODE&gt;rex&lt;/CODE&gt; till the end for your data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval x="&amp;lt;ab1:search-name&amp;gt;ABC-123-XYZ&amp;lt;/ab1:ab1:search-name&amp;gt;
    &amp;lt;ab1:search-response&amp;gt;YES&amp;lt;/ab1:search-response&amp;gt;
    &amp;lt;ab1:search-relevance&amp;gt;15&amp;lt;/ab1:search-relevance&amp;gt;
    &amp;lt;ab1:analysis/&amp;gt;
    &amp;lt;ab1:search-name&amp;gt;ABC-001-PROD&amp;lt;/ab1:search-name&amp;gt;
    &amp;lt;ab1:search-response&amp;gt;NO&amp;lt;/ab1:search-response&amp;gt;
    &amp;lt;ab1:search-relevance&amp;gt;25&amp;lt;/ab1:search-relevance&amp;gt;
    &amp;lt;ab1:analysis/&amp;gt;;
    &amp;lt;ab1:search-name&amp;gt;ABC-123-XYZ&amp;lt;/ab1:search-name&amp;gt;
    &amp;lt;ab1:search-response&amp;gt;YES&amp;lt;/ab1:search-response&amp;gt;
    &amp;lt;ab1:search-relevance&amp;gt;10&amp;lt;/ab1:search-relevance&amp;gt;
    &amp;lt;ab1:analysis/&amp;gt;
    &amp;lt;ab1:search-name&amp;gt;ABC-001-PROD&amp;lt;/ab1:search-name&amp;gt;
    &amp;lt;ab1:search-response&amp;gt;YES&amp;lt;/ab1:search-response&amp;gt;
    &amp;lt;ab1:search-relevance&amp;gt;20&amp;lt;/ab1:search-relevance&amp;gt;
    &amp;lt;ab1:analysis/&amp;gt;" 
| makemv x delim=";" 
| mvexpand x 
| rex max_match=0 field=x "-name\&amp;gt;(?&amp;lt;name&amp;gt;[^\&amp;lt;]+)" 
| rex max_match=0 field=x "-response\&amp;gt;(?&amp;lt;response&amp;gt;[^\&amp;lt;]+)" 
| rex max_match=0 field=x "-relevance\&amp;gt;(?&amp;lt;relevance&amp;gt;[^\&amp;lt;]+)" 
| eval z=mvzip(name, mvzip(response, relevance)) 
| mvexpand z 
| rex field=z "(?&amp;lt;name&amp;gt;[^,]+),(?&amp;lt;response&amp;gt;[^,]+),(?&amp;lt;relevance&amp;gt;[^,]+)" 
| table name response relevance
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Dec 2016 02:11:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203659#M59163</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-12-21T02:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Clarification on regular expression to extract XML field as multivalue field and related fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203660#M59164</link>
      <description>&lt;P&gt;I believe I have figured out the required REGEX expression - as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search query | rex "ab1:search-name&amp;gt;(?&amp;lt;search_name&amp;gt;.+)&amp;lt;" max_match=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It seems to match as required.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 03:08:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203660#M59164</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-21T03:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Clarification on regular expression to extract XML field as multivalue field and related fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203661#M59165</link>
      <description>&lt;P&gt;However still seem to be getting some strange results - will have to investigate further.&lt;BR /&gt;
&lt;STRONG&gt;Edit:&lt;/STRONG&gt; This was an issue with the data - the REGEX expression seems to be OK.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 03:16:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203661#M59165</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-21T03:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Clarification on regular expression to extract XML field as multivalue field and related fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203662#M59166</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex max_match=0 "(?ms)ab1:search-name&amp;gt;(?&amp;lt;search_name&amp;gt;[^&amp;lt;]+)"
| rex max_match=0 "(?ms)ab1:search-response&amp;gt;(?&amp;lt;search_response&amp;gt;[^&amp;lt;]+)"
| rex max_match=0 "(?ms)ab1:search-relevance&amp;gt;(?&amp;lt;search_relevance&amp;gt;[^&amp;lt;]+)"
| eval raw = mvzip(search_name, search_response, "::")
| eval raw = mvzip(raw, search_relevance, "::")
| rex field=raw mode=sed "s/[\s\r\n:]*$//"
| fields _time raw
| mvexpand raw
| rename raw AS _raw
| eval len=len(_raw)
| search len&amp;gt;0
| rex "^(?&amp;lt;search_name&amp;gt;.*)::(?&amp;lt;search_response&amp;gt;.*)::(?&amp;lt;search_relevance&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Mar 2017 23:57:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Clarification-on-regular-expression-to-extract-XML-field-as/m-p/203662#M59166</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-13T23:57:43Z</dc:date>
    </item>
  </channel>
</rss>

