<?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 use OR in regex to capture error messages from two different patterns of log files? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261123#M78373</link>
    <description>&lt;P&gt;What about:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\]\:\s(?&amp;lt;error_msg&amp;gt;.+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Oct 2015 14:18:27 GMT</pubDate>
    <dc:creator>masonmorales</dc:creator>
    <dc:date>2015-10-08T14:18:27Z</dc:date>
    <item>
      <title>How to use OR in regex to capture error messages from two different patterns of log files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261117#M78367</link>
      <description>&lt;P&gt;So I have the following log structure:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Oct  7 13:51:05, 10.96.3.29, 10.96.3.29, domain:,default [xyz][0x80e003aa][xmlparse][error] mpgw(AbcService): trans(2389130247)[request]: mismatched tag, expected meta at offset 675 of &lt;A href="http://xyz/sales/zyx" target="test_blank"&gt;http://xyz/sales/zyx&lt;/A&gt;
Oct  7 13:51:05, 10.96.3.28, 10.96.3.28, domain:,default [abc][0x80e00161][mpgw][error] source-http(XyzService): trans(363541717)[x.x.x.x]: Request processing failed: Connection terminated before request headers read because of the connection error occurs, from URL: x.x.x.x:60510
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to get the &lt;STRONG&gt;error_msg&lt;/STRONG&gt; in a variable, but since the pattern is not distinct, I have to OR the matching pattern which matches anything after &lt;CODE&gt;[request]:&lt;/CODE&gt; as Error and anything after &lt;CODE&gt;[X.X.X.X]:&lt;/CODE&gt; as Error.&lt;/P&gt;

&lt;P&gt;I created a regex which work well on a regex tester, but Splunk gives an error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'rex' command: Encountered the following error while compiling the regex 
'\[error\][^\(]+\((?&amp;lt;service&amp;gt;[^\)]+).+(trans\((\d+){8}\)\[\b(?:\d{1,3}\.){3}\d{1,3}\b\]\:\s+(?&amp;lt;error_msg&amp;gt;.+) | trans\((\d+){8}\)\[request\]\:\s+(?&amp;lt;error_msg&amp;gt;.+))': Regex: two named subpatterns have the same name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Below is my regex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[error\][^\(]+\((?&amp;lt;service&amp;gt;[^\)]+).+(trans\((\d+){8}\)\[\b(?:\d{1,3}\.){3}\d{1,3}\b\]\:\s+(?&amp;lt;error_msg&amp;gt;.+) | trans\((\d+){8}\)\[request\]\:\s+(?&amp;lt;error_msg&amp;gt;.+))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How to capture the ErrorMessage from the two pattern of log files ?&lt;BR /&gt;
Extracting the fields doesn't work either and gives a lot of junk, so I would like to go through the regex way.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 22:21:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261117#M78367</guid>
      <dc:creator>vineetc</dc:creator>
      <dc:date>2015-10-07T22:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use OR in regex to capture error messages from two different patterns of log files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261118#M78368</link>
      <description>&lt;P&gt;There is a way to make your regex more efficient/cleaner but the quickest answer is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; \[error\][^\(]+\((?&amp;lt;service&amp;gt;[^\)]+).+(trans\((\d+){8}\)\[\b(?:\d{1,3}\.){3}\d{1,3}\b\]\:\s+|trans\((\d+){8}\)\[request\]\:\s+)(?&amp;lt;error_msg&amp;gt;.+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use a pipe (|) within a capture group as an OR operator. You only specify &lt;CODE&gt;(?.+)&lt;/CODE&gt; once.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 22:47:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261118#M78368</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-10-07T22:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use OR in regex to capture error messages from two different patterns of log files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261119#M78369</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Your Base Search | rex  "\[error\][^\(]+\((?&amp;lt;service&amp;gt;[^\)]+).+(trans\((\d+){8}\)\[\b(?:\d{1,3}\.){3}\d{1,3}\b\]\:\s+(?&amp;lt;error_msg1&amp;gt;.+) | trans\((\d+){8}\)\[request\]\:\s+(?&amp;lt;error_msg2&amp;gt;.+))" | eval error_msg = coalesce(error_msg1, error_msg2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2015 22:50:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261119#M78369</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-07T22:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use OR in regex to capture error messages from two different patterns of log files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261120#M78370</link>
      <description>&lt;P&gt;I have not tested this but just eye balling it, looks like you could get the error message with something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;trans\(\d+\)\[[^\]+\]\:\s+(?&amp;lt;error_msg&amp;gt;.+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2015 22:52:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261120#M78370</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-10-07T22:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use OR in regex to capture error messages from two different patterns of log files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261121#M78371</link>
      <description>&lt;P&gt;I was able to add a character(?J) before the variable but seems like I still do get a lot of NULL in error_msg so something is there is my log which still doesnt match&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 22:55:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261121#M78371</guid>
      <dc:creator>vineetc</dc:creator>
      <dc:date>2015-10-07T22:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to use OR in regex to capture error messages from two different patterns of log files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261122#M78372</link>
      <description>&lt;P&gt;Hi vineetc,&lt;/P&gt;

&lt;P&gt;Try this regex pattern:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[error\].+?:\strans\(\d+\)\[(?:request|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]:\s(?&amp;lt;error_msg&amp;gt;.+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Oct 2015 02:55:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261122#M78372</guid>
      <dc:creator>vincenteous</dc:creator>
      <dc:date>2015-10-08T02:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to use OR in regex to capture error messages from two different patterns of log files?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261123#M78373</link>
      <description>&lt;P&gt;What about:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\]\:\s(?&amp;lt;error_msg&amp;gt;.+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Oct 2015 14:18:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-OR-in-regex-to-capture-error-messages-from-two/m-p/261123#M78373</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-10-08T14:18:27Z</dc:date>
    </item>
  </channel>
</rss>

