<?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 get the required text from rex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397526#M115388</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Please try below regex, that regex will extract output in new field called &lt;CODE&gt;ext_data&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| rex field=_raw "\&amp;lt;data\&amp;gt;\s?(?&amp;lt;ext_data&amp;gt;[^\&amp;lt;]*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;EDIT: Updated regex because I found space after &lt;CODE&gt;&amp;lt;data&amp;gt;&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Apr 2019 07:53:34 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2019-04-03T07:53:34Z</dc:date>
    <item>
      <title>How to get the required text from rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397524#M115386</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
I want to extract only the required text from Logs using rex.&lt;/P&gt;

&lt;P&gt;for instance,&lt;BR /&gt;
consider in &lt;STRONG&gt;logs&lt;/STRONG&gt; there is some data in tags i.e&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;ID&amp;gt; 100034566 &amp;lt;/ID&amp;gt; &amp;lt;data&amp;gt; This consists of DB data &amp;lt;/data&amp;gt; &amp;lt;date&amp;gt; the date is 04-03-2019 &amp;lt;/data&amp;gt;..........etc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The regular expression which  I am using is&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index = * | rex field=Msg "&amp;lt;data&amp;gt;(?&amp;lt;error&amp;gt;.*)" | table error
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;The output which I am getting is&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;error
This consists of DB data &amp;lt;/data&amp;gt; &amp;lt;date&amp;gt; the date is 04-03-2019 &amp;lt;/date&amp;gt;..........etc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I need is only the data which is present in  tag . i.e&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;REQUIRED OUTPUT&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; error
This consists of DB data
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But, The data which is suffix to that is also getting displayed, which I don't need.&lt;/P&gt;

&lt;P&gt;Can anyone help me out in this?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 07:48:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397524#M115386</guid>
      <dc:creator>saitejagayala</dc:creator>
      <dc:date>2019-04-03T07:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the required text from rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397525#M115387</link>
      <description>&lt;P&gt;Please post your current regex also as code (like you did with the sample data). Otherwise some special characters disappear.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 07:51:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397525#M115387</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-04-03T07:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the required text from rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397526#M115388</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Please try below regex, that regex will extract output in new field called &lt;CODE&gt;ext_data&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| rex field=_raw "\&amp;lt;data\&amp;gt;\s?(?&amp;lt;ext_data&amp;gt;[^\&amp;lt;]*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;EDIT: Updated regex because I found space after &lt;CODE&gt;&amp;lt;data&amp;gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 07:53:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397526#M115388</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-04-03T07:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the required text from rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397527#M115389</link>
      <description>&lt;P&gt;This should probably work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=Msg "\&amp;lt;data\&amp;gt;(?&amp;lt;error&amp;gt;[^&amp;lt;]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/tpYcTu/1"&gt;https://regex101.com/r/tpYcTu/1&lt;/A&gt;&lt;BR /&gt;
If your data indeed contains whitespace around the tags, you can strip that off using &lt;CODE&gt;| eval data=trim(data)&lt;/CODE&gt; after the rex command (can also be done by using a more complex regex).&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 07:58:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397527#M115389</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-04-03T07:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the required text from rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397528#M115390</link>
      <description>&lt;P&gt;Thanks for editing your question, the reason you're getting everything after the data tag, is because you use &lt;CODE&gt;.*&lt;/CODE&gt;, which matches anything. Have a look at the answers below for more strict regular expressions that stop at the &lt;CODE&gt;&amp;lt;&lt;/CODE&gt; character.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 07:59:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397528#M115390</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-04-03T07:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the required text from rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397529#M115391</link>
      <description>&lt;P&gt;Hi @harsmarvania57 &lt;BR /&gt;
Can you elaborate and explain the rex which you wrote?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 08:04:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397529#M115391</guid>
      <dc:creator>saitejagayala</dc:creator>
      <dc:date>2019-04-03T08:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the required text from rex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397530#M115392</link>
      <description>&lt;P&gt;Yes, I'll try my best to explain, from regex &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;CODE&gt;\&amp;lt;data\&amp;gt;&lt;/CODE&gt; is literally matching &lt;CODE&gt;&amp;lt;data&amp;gt;&lt;/CODE&gt; from your raw data&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;\s?&lt;/CODE&gt; will find white space after &lt;CODE&gt;&amp;lt;data&amp;gt;&lt;/CODE&gt; for zero or one time &lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;(?&amp;lt;ext_data&amp;gt;[^\&amp;lt;]*)&lt;/CODE&gt; will find all character before &lt;CODE&gt;&amp;lt;&lt;/CODE&gt; and store that extracted data in new field called &lt;CODE&gt;ext_data&lt;/CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 03 Apr 2019 08:12:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-required-text-from-rex/m-p/397530#M115392</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-04-03T08:12:32Z</dc:date>
    </item>
  </channel>
</rss>

