<?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 optional groups in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173691#M49818</link>
    <description>&lt;P&gt;it's a bit unclear as to exactly what you would like to extract. however... you are probably experiencing the result of having an unescaped delimeter.  you have to escape the forward slash...  check out your regex using regex101.com it's a great tool, and it will give you feedback so you can correct your stuff.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2015 17:56:59 GMT</pubDate>
    <dc:creator>rsennett_splunk</dc:creator>
    <dc:date>2015-03-10T17:56:59Z</dc:date>
    <item>
      <title>Regex optional groups</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173689#M49816</link>
      <description>&lt;P&gt;Hi guys,&lt;BR /&gt;
i'm trying to get this (simplified) regex running (for several days now):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^(?P&amp;lt;message&amp;gt;.+)(?:\s*SIP/2.0\s+(?P&amp;lt;sipaction&amp;gt;.+))?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;i also tried another flavour of this statement:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^(?P&amp;lt;message&amp;gt;.+)(?:\s*SIP/2.0\s+(?P&amp;lt;sipaction&amp;gt;.+)|\w*) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With "Extract Fields" i tested this regex on splunkweb and it works, also when i click on "View in Search" it seems to be ok.&lt;/P&gt;

&lt;P&gt;My problem is, that the field "&lt;EM&gt;sipaction&lt;/EM&gt;" is not filled out with content and everything is written to "&lt;EM&gt;message&lt;/EM&gt;" for new incoming indexed data.  I tried to implement this regex for a new sourcetype via system/local/transforms.conf &amp;amp; props.conf and also via the Webinterface with the Field-Extractor tool.&lt;/P&gt;

&lt;P&gt;I can break the problem down to the optional part of the statement: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^(?P&amp;lt;message&amp;gt;.+)[\s]*SIP/2.0\s+(?P&amp;lt;sipaction&amp;gt;.+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this case, "&lt;EM&gt;message&lt;/EM&gt;" and "&lt;EM&gt;sipaction&lt;/EM&gt;" is filled out, but i need the optional part (for a more complex regex).&lt;/P&gt;

&lt;P&gt;There is also nothing special in &lt;EM&gt;var/log/splunk/&lt;/EM&gt;.log*&lt;/P&gt;

&lt;P&gt;My splunk version is 6.2.2-255606 on rhel 2.6.32-358.el6.x86_64, with splunk version 6.1.4, the optional-regex didn't work at all, and so i upgraded to 6.2.2 .&lt;/P&gt;

&lt;P&gt;Some (simplified) data-examples from my log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2015-03-10T18:20:08.647+01:00; INFO ; Sent final response to client: 
  SIP/2.0 480 Business Logic not available

2015-03-10T18:20:08.647+01:00; INFO ; Test
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2015 17:46:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173689#M49816</guid>
      <dc:creator>f1dot4</dc:creator>
      <dc:date>2015-03-10T17:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: Regex optional groups</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173690#M49817</link>
      <description>&lt;P&gt;Your regex worked just fine on your sample data in &lt;A href="https://www.regex101.com/"&gt;regex101&lt;/A&gt; with just a few minor changes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; (?P&amp;lt;message&amp;gt;.+)(?:\s*SIP\/2\.0\s+(?P&amp;lt;sipaction&amp;gt;.+))?
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2015 17:53:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173690#M49817</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-03-10T17:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Regex optional groups</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173691#M49818</link>
      <description>&lt;P&gt;it's a bit unclear as to exactly what you would like to extract. however... you are probably experiencing the result of having an unescaped delimeter.  you have to escape the forward slash...  check out your regex using regex101.com it's a great tool, and it will give you feedback so you can correct your stuff.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2015 17:56:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173691#M49818</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2015-03-10T17:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Regex optional groups</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173692#M49819</link>
      <description>&lt;P&gt;Thank you very much, i found a way to get my regex running, finally!&lt;/P&gt;

&lt;P&gt;Only for documentation: &lt;BR /&gt;
There seems to be a inconsistency between the "Extract Fields" regex checker on splunkweb and the regex-interpreter for incoming data. A short example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?:(?!User-Agent).)*(?:User-Agent:\s+(?P&amp;lt;useragent&amp;gt;[^\s]*))?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this case &lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;regex101 returns the useragent&lt;/LI&gt;
&lt;LI&gt;the splunk regex checker on the "&lt;EM&gt;Extract Fields&lt;/EM&gt;" page does &lt;STRONG&gt;NOT&lt;/STRONG&gt; returns anything (?!)&lt;/LI&gt;
&lt;LI&gt;when i implement this regex for a sourcetype, i get values for useragent-field at searchtime
I always used the splunk regex-checker, regex101 seems to be a more reliable source! (splunk regex checker also works with my non-escaped character statement from above, while regex101 isn't)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Anyway, thanks for your help.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Example data:&lt;/EM&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2015-03-11T10:15:46.077+01:00; INFO ; HOSTNAME/P2928; 24; [RequestProcessor/ProcessBusinessLogicResponse]; Sent final response to client: SIP/2.0 480 Business Logic not available Via: SIP/2.0/UDP 0.0.0.0:0000;branch=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;rport=0000;received=0.0.0.0 To: ;tag=XXXXXXXX From: "" ;tag=XXXXXXXX Call-ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CSeq: 2001 INVITE User-Agent: APP Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, REFER, REGISTER, SUBSCRIBE, UPDATE, MESSAGE Require: timer
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Mar 2015 09:41:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-optional-groups/m-p/173692#M49819</guid>
      <dc:creator>f1dot4</dc:creator>
      <dc:date>2015-03-11T09:41:09Z</dc:date>
    </item>
  </channel>
</rss>

