<?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 regex to extract a string, but ignore the last portion if a certain string is present? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-string-but-ignore-the-last/m-p/179548#M51688</link>
    <description>&lt;P&gt;If the format of the filename is not a fixed number of period separated names, you could use something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SourceFile\=(?P&amp;lt;yourfield&amp;gt;(\w+|\.)+?)(|\.\w*B00)\sDestFile\=
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Nov 2014 16:26:15 GMT</pubDate>
    <dc:creator>davebrooking</dc:creator>
    <dc:date>2014-11-04T16:26:15Z</dc:date>
    <item>
      <title>How to write regex to extract a string, but ignore the last portion if a certain string is present?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-string-but-ignore-the-last/m-p/179546#M51686</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;Below are the two different events we have,&lt;/P&gt;

&lt;P&gt;1) DateTime="2014-11-04 06:42:35" SourceFile=&lt;STRONG&gt;ABCD.EFGH.IJKL.ABCTFILE&lt;/STRONG&gt;  DestFile=XYZA.R160001B.WERT10.A0005.H0001B00&lt;BR /&gt;
2) DateTime="2014-11-04 06:41:35" SourceFile=&lt;STRONG&gt;XYZA.ER5678A.WERT10.T0005&lt;/STRONG&gt;.J0001B00 DestFile=XYZA.R160001B.WERT10.A0005.H0001B00&lt;/P&gt;

&lt;P&gt;We need to extract the string which is highlighted in BOLD from SourceFile. The rule is to ignore the complete word where &lt;STRONG&gt;"BOO"&lt;/STRONG&gt; is present in end of the string(In 2nd event "J0001B00") or extract complete string if &lt;STRONG&gt;"BOO"&lt;/STRONG&gt; is not present (in 1st Event)&lt;/P&gt;

&lt;P&gt;We wrote a regEx which will match ---&amp;gt;   (?i)SourceFile\W(.&lt;EM&gt;?).\w+\s&lt;BR /&gt;
**ABCD.EFGH.IJKL&lt;/EM&gt;* from 1st event ==&amp;gt; here "&lt;STRONG&gt;ABCTFILE&lt;/STRONG&gt;" is missing&lt;BR /&gt;
&lt;STRONG&gt;XYZA.ER5678A.WERT10.T0005&lt;/STRONG&gt; from 2nd event&lt;/P&gt;

&lt;P&gt;We have issues in extracting from 1st event. &lt;/P&gt;

&lt;P&gt;&lt;A href="http://rubular.com/r/O6tB73XSpz" target="_blank"&gt;Online RegEx Editor with above Events&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://rubular.com/r/O6tB73XSpz" target="_blank"&gt;http://rubular.com/r/O6tB73XSpz&lt;/A&gt;&lt;BR /&gt;
Can any one please help to write proper regEx which will extract both string&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Smith&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:59:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-string-but-ignore-the-last/m-p/179546#M51686</guid>
      <dc:creator>Smith_Splunk</dc:creator>
      <dc:date>2020-09-28T17:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a string, but ignore the last portion if a certain string is present?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-string-but-ignore-the-last/m-p/179547#M51687</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;

&lt;P&gt;Try with this regex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SourceFile\=(?&amp;lt;yourfield&amp;gt;(\w+|\.){7})(\sDestFile|\.\w*B00\s)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 15:13:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-string-but-ignore-the-last/m-p/179547#M51687</guid>
      <dc:creator>gfuente</dc:creator>
      <dc:date>2014-11-04T15:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to write regex to extract a string, but ignore the last portion if a certain string is present?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-string-but-ignore-the-last/m-p/179548#M51688</link>
      <description>&lt;P&gt;If the format of the filename is not a fixed number of period separated names, you could use something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SourceFile\=(?P&amp;lt;yourfield&amp;gt;(\w+|\.)+?)(|\.\w*B00)\sDestFile\=
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Nov 2014 16:26:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-regex-to-extract-a-string-but-ignore-the-last/m-p/179548#M51688</guid>
      <dc:creator>davebrooking</dc:creator>
      <dc:date>2014-11-04T16:26:15Z</dc:date>
    </item>
  </channel>
</rss>

