<?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: OR (|) condition in regular expression in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64658#M15974</link>
    <description>&lt;P&gt;Not sure if you can use an OR to extract one field of another.&lt;BR /&gt;
usually this is the opposite, you have one field with 1 value or another.&lt;/P&gt;

&lt;P&gt;try to do in 2 steps &lt;/P&gt;

&lt;PRE&gt;
 rex "(?&lt;ITEMALL&gt;((\d{0,3})|([^#]+))
&lt;/ITEMALL&gt;&lt;/PRE&gt;

&lt;P&gt;then an eval with conditions to extract the fields ItemDetail OR the field ItemDescription from the field ItemAll.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Dec 2012 17:28:38 GMT</pubDate>
    <dc:creator>yannK</dc:creator>
    <dc:date>2012-12-14T17:28:38Z</dc:date>
    <item>
      <title>OR (|) condition in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64657#M15973</link>
      <description>&lt;P&gt;I am missing something in my regular expression&lt;BR /&gt;
I am having similar log and I can do with two regex but I want to combine all search in single regex.&lt;/P&gt;

&lt;P&gt;Here is my 2 log events&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;I20121126 16:50:50.949136  7416 r_c.cpp:42] TTT.OUT.MESSAGE:121 [R10] [LOG-SG1/REPORT.PRINT.SOD-EB.EOD.REPORT.PRINT] [T24.System.Metrics] READ.SIZE#HMLL1107506#26 NOV 2012#16:50:51#1#F.STANDARD.SELECTION#FD.FID.ORDER#INT#EB.EOD.REPORT.PRINT#7852#0#4

I20121126 16:57:22.375921  7416 r_c.cpp:42] TTT.IN.MESSAGE:121 [R10] [LOG-SG1/BATCH.DATE.RESET-BATCH.DATE.RESET] [T24.System.Metrics] JOB.STARTED#HMLL1107506#26 NOV 2012#16:57:22#1#O999#SG0010001_20120131-SG1/BATCH.DATE.RESET_BATCH.DATE.RESET_1#DailyRollingOTCCRAN.SY1202601307#BATCH.DATE.RESET#1#0#4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is my regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[[\w]{0,}-{0,1}(?P&amp;lt;CompanyName&amp;gt;\w\w\w)[^\s]+\s\[(?P&amp;lt;RecordType&amp;gt;[\w\.]{0,})\]\s(?P&amp;lt;JobStatus&amp;gt;[^#]+)#(?P&amp;lt;ServerName&amp;gt;[^#]+)#(?P&amp;lt;ServerDate&amp;gt;[^#]+)#(?P&amp;lt;ServerTime&amp;gt;[^#]+)#(?P&amp;lt;MetricsCount&amp;gt;[^#]+)#(?P&amp;lt;Stage&amp;gt;\w{0,1})(?P&amp;lt;ItemDetail&amp;gt;\d{0,3})|(?P&amp;lt;ItemDescription&amp;gt;[^#]+)#(?P&amp;lt;TopKey&amp;gt;[^#]+)#(?P&amp;lt;TransactionRef&amp;gt;[^#]{0,})#(?P&amp;lt;Application&amp;gt;[^#]{0,})#(?P&amp;lt;ResponseTime&amp;gt;\d+)#(?P&amp;lt;Unused&amp;gt;\d)#(?P&amp;lt;PortNumber&amp;gt;\d)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;above regex will select only one event&lt;BR /&gt;
something wrong here&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;**(?P&amp;lt;Stage&amp;gt;\w{0,1})(?P&amp;lt;ItemDetail&amp;gt;\d{0,3})|(?P&amp;lt;ItemDescription&amp;gt;[^#]+)**
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;can you please tell me what I am missing?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2012 17:16:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64657#M15973</guid>
      <dc:creator>jangid</dc:creator>
      <dc:date>2012-12-14T17:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: OR (|) condition in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64658#M15974</link>
      <description>&lt;P&gt;Not sure if you can use an OR to extract one field of another.&lt;BR /&gt;
usually this is the opposite, you have one field with 1 value or another.&lt;/P&gt;

&lt;P&gt;try to do in 2 steps &lt;/P&gt;

&lt;PRE&gt;
 rex "(?&lt;ITEMALL&gt;((\d{0,3})|([^#]+))
&lt;/ITEMALL&gt;&lt;/PRE&gt;

&lt;P&gt;then an eval with conditions to extract the fields ItemDetail OR the field ItemDescription from the field ItemAll.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2012 17:28:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64658#M15974</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2012-12-14T17:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: OR (|) condition in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64659#M15975</link>
      <description>&lt;P&gt;It is possible to have a | between fields in rex, it'll extract the first field that matches - even if the second one would have matched as well.&lt;/P&gt;

&lt;P&gt;Not sure if this is what the OP wants though, it's not a logical OR in the sense of "this, that, or both" but rather a "this if it exists, else that if it exists, else neither" &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2012 19:30:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64659#M15975</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2012-12-14T19:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: OR (|) condition in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64660#M15976</link>
      <description>&lt;P&gt;You can use OR in regex, you just need to group the options together in a non-capturing group&lt;/P&gt;

&lt;P&gt;i.e.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?:(?P&amp;lt;ItemDetail&amp;gt;\d{0,3})|(?P&amp;lt;ItemDescription&amp;gt;[^#]+))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will set ItemDescription in the 1st example log.&lt;/P&gt;

&lt;P&gt;You might prefer&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?:(?P&amp;lt;ItemDetail&amp;gt;\d{0,3})|\.(?P&amp;lt;ItemDescription&amp;gt;[^#]+))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to strip the '.' after Stage ( F in the 1st example ) as it sticks to the front of the ItemDescription&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2012 20:23:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/OR-condition-in-regular-expression/m-p/64660#M15976</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2012-12-14T20:23:06Z</dc:date>
    </item>
  </channel>
</rss>

