<?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: rex expression without resorting to mode=sed in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179989#M51808</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;
I'm not sure why you want to avoid &lt;CODE&gt;mode=sed&lt;/CODE&gt;. It seems like the correct way. In any case, if you do want to avoid it, the following should do the trick of recognising an A or B at the end:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=host "(?&amp;lt;host&amp;gt;.*)[A,B]$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
    <pubDate>Wed, 13 Aug 2014 10:12:53 GMT</pubDate>
    <dc:creator>echalex</dc:creator>
    <dc:date>2014-08-13T10:12:53Z</dc:date>
    <item>
      <title>rex expression without resorting to mode=sed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179988#M51807</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;

&lt;P&gt;I am changing a string in the host field of output with this format&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ZX3B1093200198A
ZX3B1093200198B
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The last alpha character is either 'A' or 'B' &lt;BR /&gt;
(with that some might be able to guess what the platform is)&lt;/P&gt;

&lt;P&gt;I can do precisely that with a simple &lt;EM&gt;sed&lt;/EM&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=relevant index name sourcetype=relevant source type | rex mode=sed field=host "s/[A-B]$//"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That, not surprisingly, works. But I would like to do the same with rex, but without resorting to  &lt;EM&gt;sed&lt;/EM&gt;, which doesn't get used elsewhere.&lt;/P&gt;

&lt;P&gt;This works;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=relevant index name sourcetype=relevant source type | rex field=host "(?&amp;lt;host&amp;gt;.*).{1}"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I want to specify that only the characters 'A' or 'B' (always uppercase) are removed if present. &lt;/P&gt;

&lt;P&gt;I tried  &lt;CODE&gt;(?&amp;lt;host&amp;gt;.*[A,B]).{1}&lt;/CODE&gt; and a few other similar combinations but can't achieve that very last bit.&lt;/P&gt;

&lt;P&gt;Any pointers or assistance gratefully received!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2014 08:59:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179988#M51807</guid>
      <dc:creator>avalon</dc:creator>
      <dc:date>2014-08-13T08:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression without resorting to mode=sed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179989#M51808</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I'm not sure why you want to avoid &lt;CODE&gt;mode=sed&lt;/CODE&gt;. It seems like the correct way. In any case, if you do want to avoid it, the following should do the trick of recognising an A or B at the end:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=host "(?&amp;lt;host&amp;gt;.*)[A,B]$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2014 10:12:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179989#M51808</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2014-08-13T10:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression without resorting to mode=sed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179990#M51809</link>
      <description>&lt;P&gt;Firstly, I do agree with @echalex about best way for this requirement is to use rex with sed. &lt;/P&gt;

&lt;P&gt;Keeping your requirement of removing 'A' or 'B' from last part to be removed, if present, try one of following options (run anywhere sample, added rex-sed example as well for comparison)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|gentimes start=-1 | eval host="ZX3B1093200198A ZX3B1093200198B ZX3B1093200198" | table host | makemv host | mvexpand host | eval host1=host 
| rex mode=sed field=host1 "s/[A-B]$//" 
| rex field=host "(?&amp;lt;host2&amp;gt;.*[^AB])" 
| eval host3=replace(host,"((\w+\d+)*)([AB])$","\1") 
| eval host4=rtrim(host,"AB")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Aug 2014 19:45:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179990#M51809</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-08-13T19:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression without resorting to mode=sed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179991#M51810</link>
      <description>&lt;P&gt;Terrific!&lt;BR /&gt;
All for the need of a bracket in the right place!&lt;/P&gt;

&lt;P&gt;The sed routine really looks the most efficient!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2014 20:08:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179991#M51810</guid>
      <dc:creator>avalon</dc:creator>
      <dc:date>2014-08-13T20:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: rex expression without resorting to mode=sed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179992#M51811</link>
      <description>&lt;P&gt;Great answer! Nice to see all of the options available.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2014 20:09:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-expression-without-resorting-to-mode-sed/m-p/179992#M51811</guid>
      <dc:creator>avalon</dc:creator>
      <dc:date>2014-08-13T20:09:18Z</dc:date>
    </item>
  </channel>
</rss>

