<?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 write the regex to extract fields from my sample XML data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230842#M68456</link>
    <description>&lt;P&gt;There are three reasons the rex commands are not working:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1) The characters between "&amp;lt;sytems&amp;gt;" and the following tag are not accounted for.
2) Slashes must be escaped.
3) The last rex has closing tags in the wrong order.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These rex commands should work, although @jplumsdaine22's answer is better.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=info "&amp;lt;sys_Id&amp;gt;(?&amp;lt;sytems&amp;gt;.*?)&amp;lt;\/sys_Id&amp;gt;"
| rex field=Info "&amp;lt;name&amp;gt;(?&amp;lt;Name&amp;gt;.*?)&amp;lt;\/name&amp;gt;"
| rex field=Info "&amp;lt;version&amp;gt;(?&amp;lt;Version&amp;gt;.*?)&amp;lt;\/version&amp;gt;"
| rex field=Info "&amp;lt;ip_address&amp;gt;(?&amp;lt;Ip_Address&amp;gt;.*?)&amp;lt;\/ip_address&amp;gt;"
| rex field=Info "&amp;lt;connector_Id&amp;gt;(?&amp;lt;Connector_Ids&amp;gt;.*?)&amp;lt;\/connector_Id&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Mar 2016 20:35:49 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2016-03-03T20:35:49Z</dc:date>
    <item>
      <title>How to write the regex to extract fields from my sample XML data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230840#M68454</link>
      <description>&lt;P&gt;Sample data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;             &amp;lt;id&amp;gt;WGBSTH8180T&amp;lt;/id&amp;gt;
         &amp;lt;sytems&amp;gt;
         &amp;lt;sys_Id&amp;gt;14502&amp;lt;/sys_Id&amp;gt;
         &amp;lt;name&amp;gt;GYS&amp;lt;/name&amp;gt;
         &amp;lt;version&amp;gt;9901&amp;lt;/version&amp;gt;
         &amp;lt;ip_address&amp;gt;172.11.11.212&amp;lt;/ip_address&amp;gt;
         &amp;lt;connector&amp;gt;
         &amp;lt;connector_Id&amp;gt;TH818AST001A&amp;lt;/connector_Id&amp;gt;&amp;lt;/connector&amp;gt;&amp;lt;/sytems&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can able to get the value &lt;CODE&gt;WGBSTH8180T&lt;/CODE&gt; with the regex like &lt;CODE&gt;| rex field=Info "(?ms)(?.*?)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Can anyone help me out with how to extract the values sys_Id (systems), name (systems), version (systems), ip_address (systems), and connector_Id (connector) from the data above?&lt;/P&gt;

&lt;P&gt;I'm using regex as mentioned below, but its not working. Please help me out to write regex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     | rex field=Info "(?ms)&amp;lt;sytems&amp;gt;&amp;lt;sys_Id&amp;gt;(?&amp;lt;sytems&amp;gt;.*?)&amp;lt;/sys_Id&amp;gt;&amp;lt;/sytems&amp;gt;"
     | rex field=Info "(?ms)&amp;lt;sytems&amp;gt;&amp;lt;name&amp;gt;(?&amp;lt;Name&amp;gt;.*?)&amp;lt;/name&amp;gt;&amp;lt;/sytems&amp;gt;"
     | rex field=Info "(?ms)&amp;lt;sytems&amp;gt;&amp;lt;version&amp;gt;(?&amp;lt;Version&amp;gt;.*?)&amp;lt;/version&amp;gt;&amp;lt;/sytems&amp;gt;"
     | rex field=Info "(?ms)&amp;lt;sytems&amp;gt;&amp;lt;ip_address&amp;gt;(?&amp;lt;Ip_Address&amp;gt;.*?)&amp;lt;/ip_address&amp;gt;&amp;lt;/sytems&amp;gt;"
     | rex field=Info "(?ms)&amp;lt;sytems&amp;gt;&amp;lt;connector&amp;gt;&amp;lt;connector_Id&amp;gt;(?&amp;lt;Connector_Ids&amp;gt;.*?)&amp;lt;/sys_Id&amp;gt;&amp;lt;/connector_Id&amp;gt;&amp;lt;/sytems&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:58:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230840#M68454</guid>
      <dc:creator>Shan</dc:creator>
      <dc:date>2020-09-29T08:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to extract fields from my sample XML data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230841#M68455</link>
      <description>&lt;P&gt;If the log files you are indexing are valid xml, just use the &lt;CODE&gt;spath&lt;/CODE&gt; command. See the search reference&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.3/SearchReference/Spath"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.3/SearchReference/Spath&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 20:19:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230841#M68455</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-03-03T20:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to extract fields from my sample XML data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230842#M68456</link>
      <description>&lt;P&gt;There are three reasons the rex commands are not working:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1) The characters between "&amp;lt;sytems&amp;gt;" and the following tag are not accounted for.
2) Slashes must be escaped.
3) The last rex has closing tags in the wrong order.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These rex commands should work, although @jplumsdaine22's answer is better.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=info "&amp;lt;sys_Id&amp;gt;(?&amp;lt;sytems&amp;gt;.*?)&amp;lt;\/sys_Id&amp;gt;"
| rex field=Info "&amp;lt;name&amp;gt;(?&amp;lt;Name&amp;gt;.*?)&amp;lt;\/name&amp;gt;"
| rex field=Info "&amp;lt;version&amp;gt;(?&amp;lt;Version&amp;gt;.*?)&amp;lt;\/version&amp;gt;"
| rex field=Info "&amp;lt;ip_address&amp;gt;(?&amp;lt;Ip_Address&amp;gt;.*?)&amp;lt;\/ip_address&amp;gt;"
| rex field=Info "&amp;lt;connector_Id&amp;gt;(?&amp;lt;Connector_Ids&amp;gt;.*?)&amp;lt;\/connector_Id&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2016 20:35:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230842#M68456</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-03-03T20:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to extract fields from my sample XML data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230843#M68457</link>
      <description>&lt;P&gt;The following regex matches in 66 or less steps.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=info "\&amp;lt;id\&amp;gt;(?&amp;lt;id&amp;gt;[^\&amp;lt;]+)\&amp;lt;[^\&amp;lt;]+\&amp;lt;[^\s]+\&amp;gt;\s+\&amp;lt;sys_Id\&amp;gt;(?&amp;lt;sys_Id&amp;gt;[^\&amp;lt;]+)\&amp;lt;[^\&amp;lt;]+\&amp;lt;(?&amp;lt;name&amp;gt;[^\&amp;lt;]+)\&amp;lt;[^\&amp;lt;]+\&amp;lt;(?&amp;lt;version&amp;gt;[^\&amp;lt;]+)\&amp;lt;[^\&amp;lt;]+\&amp;lt;ip_address\&amp;gt;(?&amp;lt;ip_address&amp;gt;[^\&amp;lt;]+)\&amp;lt;[^\&amp;lt;]+\&amp;lt;[^\s]+\&amp;gt;\s+\&amp;lt;(?&amp;lt;connector_id&amp;gt;[^\&amp;lt;]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All the answers given so far will work.  Have poor or non-optimized regex statements for large dataset cause poor search performance. What work well for 10k events doesn't work well 1Billion events.   &lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 23:05:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230843#M68457</guid>
      <dc:creator>bmacias84</dc:creator>
      <dc:date>2016-03-03T23:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to extract fields from my sample XML data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230844#M68458</link>
      <description>&lt;P&gt;Also see this: &lt;A href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags"&gt;http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 10:25:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230844#M68458</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-03-04T10:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to extract fields from my sample XML data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230845#M68459</link>
      <description>&lt;P&gt;Lots of threads are out there about the topic such as - &lt;A href="https://answers.splunk.com/answers/49521/splunk-why-must-xml-sources-be-so-complicated.html"&gt;https://answers.splunk.com/answers/49521/splunk-why-must-xml-sources-be-so-complicated.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 17:05:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-extract-fields-from-my-sample-XML-data/m-p/230845#M68459</guid>
      <dc:creator>ddrillic</dc:creator>
      <dc:date>2016-03-04T17:05:45Z</dc:date>
    </item>
  </channel>
</rss>

