<?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 Find First Match of OR in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220834#M64888</link>
    <description>&lt;P&gt;Good stuff!&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2016 20:22:24 GMT</pubDate>
    <dc:creator>ktugwell_splunk</dc:creator>
    <dc:date>2016-04-22T20:22:24Z</dc:date>
    <item>
      <title>RegEx to Find First Match of OR</title>
      <link>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220829#M64883</link>
      <description>&lt;P&gt;Hi, banging my head...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;04/22/2016 09:23:50,865 - ERROR - exception occurred --- FOO BAR
Severity:        Error
Message:         Timeout expired. 
MachineName:     MY MACHINE


04/22/2016 09:23:56,318 - ERROR - exception occurred --- System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have a single log file that contains the two formats.  What I want to do is if the entry has "Message:", then make this the extracted field ErrorMessage, Else If the entry have "ERROR" then, make this the extracted field ErrorMessage.&lt;/P&gt;

&lt;P&gt;(?:Message:)|(?:ERROR -)|\s+(?P(?:[^\n]*))  this is the regex I started with and modified with few things and I still can't get it right. &lt;/P&gt;

&lt;P&gt;Help appreciated.&lt;/P&gt;

&lt;P&gt;Thank you,&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 18:50:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220829#M64883</guid>
      <dc:creator>chrisboy68</dc:creator>
      <dc:date>2016-04-22T18:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx to Find First Match of OR</title>
      <link>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220830#M64884</link>
      <description>&lt;P&gt;You could do 2 field extractions both producing the same field name &lt;CODE&gt;ErrorMessage&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yoursourcetype]
EXTRACT-1 = Message:\s+(?&amp;lt;ErrorMessage&amp;gt;[A-Za-z0-9 ]+)
EXTRACT-2 = \d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}:\d{2},\d{3}\s-\sERROR\s-\s(?&amp;lt;ErrorMessage&amp;gt;.+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That regex isn't the best in the world but you can keep tweaking it to suit your needs&lt;/P&gt;

&lt;P&gt;Be sure to add all the possible characters you may see after "Message:" in this part of the regex &lt;CODE&gt;[A-Za-z0-9 ]&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 19:04:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220830#M64884</guid>
      <dc:creator>ktugwell_splunk</dc:creator>
      <dc:date>2016-04-22T19:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx to Find First Match of OR</title>
      <link>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220831#M64885</link>
      <description>&lt;P&gt;Thanks, but wouldn't that still execute both EXTRACTs? I just want One or the Other.&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 19:09:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220831#M64885</guid>
      <dc:creator>chrisboy68</dc:creator>
      <dc:date>2016-04-22T19:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx to Find First Match of OR</title>
      <link>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220832#M64886</link>
      <description>&lt;P&gt;Give it a try, I may be wrong, but I think you'll only only see EXTRACT-2 as ErrorMessage if EXTRACT-1 doesn't exist. Either that or it'll create a multi value field.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 19:17:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220832#M64886</guid>
      <dc:creator>ktugwell_splunk</dc:creator>
      <dc:date>2016-04-22T19:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx to Find First Match of OR</title>
      <link>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220833#M64887</link>
      <description>&lt;P&gt;Thanks. You look to be correct! Its working.&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 20:20:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220833#M64887</guid>
      <dc:creator>chrisboy68</dc:creator>
      <dc:date>2016-04-22T20:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx to Find First Match of OR</title>
      <link>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220834#M64888</link>
      <description>&lt;P&gt;Good stuff!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 20:22:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/RegEx-to-Find-First-Match-of-OR/m-p/220834#M64888</guid>
      <dc:creator>ktugwell_splunk</dc:creator>
      <dc:date>2016-04-22T20:22:24Z</dc:date>
    </item>
  </channel>
</rss>

