<?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: Regex to extract numbers from non unique string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252913#M75685</link>
    <description>&lt;P&gt;One further question... I end up with 3 values but I only need one. The XML component for the value I am after also contains &lt;CODE&gt;&amp;lt;_0:AnnualAmount&amp;gt;&lt;/CODE&gt; could I somehow use this in the xpath query to limit the results returned ?&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Mon, 29 Aug 2016 05:11:54 GMT</pubDate>
    <dc:creator>ahogbin</dc:creator>
    <dc:date>2016-08-29T05:11:54Z</dc:date>
    <item>
      <title>Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252909#M75681</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am hoping that someone with far more knowledge than myself can help with a bit of a puzzling problem I have with trying to extract some numbers from a non unique string&lt;/P&gt;

&lt;P&gt;The numbers I am trying to extract are in the &lt;CODE&gt;&amp;lt;_0:EndOfTermAmount&amp;gt;999.30&amp;lt;/_0:EndOfTermAmount&amp;gt;&lt;/CODE&gt;&lt;BR /&gt;
but this issue I have is that this is no a unique identifier (ie the same string appears in several other places within the XML.&lt;/P&gt;

&lt;P&gt;The only unique thing is that the numbers I am after are always contained within &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;_0:AALNet&amp;gt;
            &amp;lt;_0:AnnualAmount&amp;gt;0.00&amp;lt;/_0:AnnualAmount&amp;gt;
            &amp;lt;_0:MonthlyAmount&amp;gt;0.00&amp;lt;/_0:MonthlyAmount&amp;gt;
            &amp;lt;_0:FortnightlyAmount&amp;gt;0.00&amp;lt;/_0:FortnightlyAmount&amp;gt;
            &amp;lt;_0:EndOfTermAmount&amp;gt;999.30&amp;lt;/_0:EndOfTermAmount&amp;gt;
            &amp;lt;_0:ComparisonAmount&amp;gt;0.00&amp;lt;/_0:ComparisonAmount&amp;gt;
            &amp;lt;_0:InstallmentGapAmount&amp;gt;0.00&amp;lt;/_0:InstallmentGapAmount&amp;gt;
          &amp;lt;/_0:AALNet&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there a way of using the _0:AALNET as a key to then extract the required number (in this case 999.30) using regex (or some other means) ? - the length of the numbers to be extracted can vary.&lt;/P&gt;

&lt;P&gt;I am totally stumped on this one so any help or pointers will be greatly appreciated.&lt;/P&gt;

&lt;P&gt;Cheers.&lt;/P&gt;

&lt;P&gt;Alastair&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 04:18:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252909#M75681</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2016-08-29T04:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252910#M75682</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?s)&amp;lt;_0:AALNet&amp;gt;.*&amp;lt;_0:EndOfTermAmount&amp;gt;(?P&amp;lt;mynumber&amp;gt;[^&amp;lt;]+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(?s) modifies to include newline characters - i.e. make it a single line.  And "mynumber" will be 999.30&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 04:35:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252910#M75682</guid>
      <dc:creator>svenwendler</dc:creator>
      <dc:date>2016-08-29T04:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252911#M75683</link>
      <description>&lt;P&gt;If you're doing this in a search, could you use either the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/xpath"&gt;xpath&lt;/A&gt; command or the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;spath&lt;/A&gt; command to help? &lt;/P&gt;

&lt;P&gt;Based on your fragment, and not an entire sample, maybe something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | xpath outfield=EndOfTermAmount "//*[local-name()='AALNet']/*[local-name()='EndOfTermAmount']"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(Depending on the overall structure of the XML, there could be nuances to xpath and spath, but hopefully this points you in a good direction... stupid xpath and namespace issues... you may be interested in &lt;A href="http://stackoverflow.com/a/10990253/504685"&gt;this stack overflow answer&lt;/A&gt; also &lt;A href="http://stackoverflow.com/a/6397369/504685"&gt;this other stackoverflow answer&lt;/A&gt;)&lt;/P&gt;

&lt;P&gt;EDIT TO ADD: Out of frustration with the xpath command and it not supporting namespaces unless done in a really ugly manner using &lt;CODE&gt;namespace-uri()=&lt;/CODE&gt; at each level, I logged P4 case 389100 asking to have namespace binding added to the xpath command.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 04:43:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252911#M75683</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2016-08-29T04:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252912#M75684</link>
      <description>&lt;P&gt;Perfect... both options worked it is just the xpath command allows me to extract 'all' variances (I had not realised what I thought was unique was repeated).&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 05:03:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252912#M75684</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2016-08-29T05:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252913#M75685</link>
      <description>&lt;P&gt;One further question... I end up with 3 values but I only need one. The XML component for the value I am after also contains &lt;CODE&gt;&amp;lt;_0:AnnualAmount&amp;gt;&lt;/CODE&gt; could I somehow use this in the xpath query to limit the results returned ?&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 05:11:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252913#M75685</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2016-08-29T05:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252914#M75686</link>
      <description>&lt;P&gt;xpath itself is a rather &lt;A href="https://www.w3.org/TR/xpath-31/"&gt;powerful language&lt;/A&gt; with lots of functions available and all kinds of ways to add additional qualifiers. (I'm not quite sure what version Splunk uses under the hood, so couldn't tell you what would work and what wouldn't without trying some things)... &lt;/P&gt;

&lt;P&gt;But taking a whack at your request, select an EndOfTermAmount whose parent AALNet element also has a child AnnualAmount element would be something like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | xpath outfield=test "//*[local-name()='AALNet' and *[local-name()='AnnualAmount']]/*[local-name()='EndOfTermAmount']"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I figured that out from another &lt;A href="http://stackoverflow.com/a/11560718/504685"&gt;stackoverflow post&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 05:29:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252914#M75686</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2016-08-29T05:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252915#M75687</link>
      <description>&lt;P&gt;Works a treat.. thank you so much.&lt;/P&gt;

&lt;P&gt;Alastair&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 05:32:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252915#M75687</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2016-08-29T05:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252916#M75688</link>
      <description>&lt;P&gt;One other note, I see you're using the "award points" link. Instead of doing that, for content (questions, answers, comments) that you believe is particularly good (helpful, useful, amusing, etc.), you can instead use the vote up link (^). Not only does this not cost you any karma points, but it marks that the content was particularly worthwhile to someone (and still awards karma points to the creator of said worthwhile content). &lt;/P&gt;

&lt;P&gt;As a moderator, I gave you the 101 points that you gave away in this manner so far. While you can still use award points for something that is mind blowing beyond belief, that requires both a vote up and then extra points, save your karma for those special occasions, and vote first &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 05:47:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252916#M75688</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2016-08-29T05:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract numbers from non unique string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252917#M75689</link>
      <description>&lt;P&gt;Thank you so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 06:27:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-numbers-from-non-unique-string/m-p/252917#M75689</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2016-08-29T06:27:23Z</dc:date>
    </item>
  </channel>
</rss>

