<?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 remove optional trailing text from field with transforms/props in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356850#M105571</link>
    <description>&lt;P&gt;Hi bowesmana, &lt;/P&gt;

&lt;P&gt;try out this regex and see if it will do the trick.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/3MSGhl/2"&gt;https://regex101.com/r/3MSGhl/2&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(.+)(?:((?i)\sends\s[1]?[0-9]\s[ap]\.m\.))$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 17 Jun 2017 10:13:45 GMT</pubDate>
    <dc:creator>horsefez</dc:creator>
    <dc:date>2017-06-17T10:13:45Z</dc:date>
    <item>
      <title>Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356849#M105570</link>
      <description>&lt;P&gt;I have a field called Title, where it may sometimes end with the text&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Ends 9 P.M.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or varying case related variants.&lt;/P&gt;

&lt;P&gt;I can easily do this in my search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex mode=sed field=Title "s/(?i) Ends 9.?p.?m.?//"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which performs the job nicely, but I want to be able to do this as standard, so I tried setting up a transform and field extraction with the following regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(.*)((?i) ends [0-9]*.?[ap].?m)?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but the optional ? at the end of the 'ends...' group means that the first (.*) will capture all text, including the 'ends...' section, so the result is no change.&lt;/P&gt;

&lt;P&gt;If I get rid of the last ? then it works for fields that have the 'ends...' but not for those fields that don't so they lose their value.&lt;/P&gt;

&lt;P&gt;Any help on the right regex or a way to setup a 'sed' style regex in conf?&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2017 07:44:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356849#M105570</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2017-06-17T07:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356850#M105571</link>
      <description>&lt;P&gt;Hi bowesmana, &lt;/P&gt;

&lt;P&gt;try out this regex and see if it will do the trick.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/3MSGhl/2"&gt;https://regex101.com/r/3MSGhl/2&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(.+)(?:((?i)\sends\s[1]?[0-9]\s[ap]\.m\.))$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Jun 2017 10:13:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356850#M105571</guid>
      <dc:creator>horsefez</dc:creator>
      <dc:date>2017-06-17T10:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356851#M105572</link>
      <description>&lt;P&gt;That has the same problem as my original, i.e. it does not capture anything in the capture group &lt;EM&gt;unless&lt;/EM&gt; the text does have the trailing "ends..." phrase, e.g.&lt;/P&gt;

&lt;P&gt;The phrase&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Weekend Unreserved
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;gets an empty capture group 1 as the regex requires the "ends..." to be present to result in a match&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jun 2017 05:04:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356851#M105572</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2017-06-18T05:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356852#M105573</link>
      <description>&lt;P&gt;I could make two alternatives within the regex, but then I am not sure how to assign the correct numbered capture group to the Title.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jun 2017 05:12:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356852#M105573</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2017-06-18T05:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356853#M105574</link>
      <description>&lt;P&gt;How about this one?&lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/3MSGhl/3"&gt;https://regex101.com/r/3MSGhl/3&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jun 2017 09:01:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356853#M105574</guid>
      <dc:creator>horsefez</dc:creator>
      <dc:date>2017-06-18T09:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356854#M105575</link>
      <description>&lt;P&gt;Still has the same issue, how does that work with transforms.conf, where the assignment is done with &lt;/P&gt;

&lt;P&gt;Title::$X &lt;/P&gt;

&lt;P&gt;where X is the capture group #. Unless it's always the same number how do you assign more than one capture group to the same field?&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jun 2017 10:01:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356854#M105575</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2017-06-18T10:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356855#M105576</link>
      <description>&lt;P&gt;Try this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?i)(^.*(?=\s*ends\s+\d+\s?[ap]\.?m\.?.*)|^.*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is a case-insensitive flag &lt;CODE&gt;(?i)&lt;/CODE&gt; followed by a single capture group which has two options.  The first option is anything, followed by a positive lookahead &lt;CODE&gt;(?=&lt;/CODE&gt; for a value like " ends 9 pm".  You'll notice I've allowed for 2-digit hours, etc.  If that one fails, the second option takes everything.  Both options require the match to start at the beginning of the string, with the first one ending at the start of the positive lookahead, and the second option taking the entire string.    &lt;/P&gt;</description>
      <pubDate>Sun, 18 Jun 2017 22:54:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356855#M105576</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-18T22:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356856#M105577</link>
      <description>&lt;P&gt;Ah, that's the trick with the positive lookahead... That single capture group is the key, which means I can use Title::$1 in the transforms.conf and it works.&lt;/P&gt;

&lt;P&gt;Out of interest, would lookaround work to remove prefixes to strings? I played around with a few attempts, but I don't see that it would.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 10:22:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356856#M105577</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2017-06-19T10:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to remove optional trailing text from field with transforms/props</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356857#M105578</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Updated&lt;/STRONG&gt;. Correct tool is &lt;EM&gt;definitely&lt;/EM&gt; not lookaround.  &lt;/P&gt;

&lt;P&gt;Just need to take group 2 from this one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^(drop this prefix )?(.*)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 11:52:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-remove-optional-trailing-text-from-field-with/m-p/356857#M105578</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-19T11:52:22Z</dc:date>
    </item>
  </channel>
</rss>

