<?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: Unable to extract optional fields in splunk through regex in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144528#M12697</link>
    <description>&lt;P&gt;I think this will also work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.+\[(?&amp;lt;FIELD1&amp;gt;[^,]+)\,?(?&amp;lt;FIELD2&amp;gt;[0-9-]+)?\,(?&amp;lt;FIELD3&amp;gt;\w+)\,?(?&amp;lt;FIELD4&amp;gt;\S+)?\]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 15 Nov 2013 16:20:32 GMT</pubDate>
    <dc:creator>dmaislin_splunk</dc:creator>
    <dc:date>2013-11-15T16:20:32Z</dc:date>
    <item>
      <title>Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144525#M12694</link>
      <description>&lt;P&gt;Hi, I have logs some what like this&lt;/P&gt;

&lt;P&gt;......[ABC] - [YUP1,AConsole]&lt;BR /&gt;
......[PQR] - [YUP1,PConsole]&lt;BR /&gt;
......[ZAD] - [YUP1,DConsole]&lt;BR /&gt;
......[SID] - [TYU3,2013-08-29,QConsole]&lt;BR /&gt;
......[POP] - [TYU3,2013-08-30,TConsole]&lt;BR /&gt;
......[IOL] - [TYU3,2013-09-01,XConsole]&lt;BR /&gt;
......[DSW] - [GKFO,2013-09-12,iConsole,Payment1]&lt;BR /&gt;
......[ESD] - [IOSD,2013-09-13,iConsole,Payment2]&lt;BR /&gt;
......[ABC] - [YUP1,AConsole]&lt;BR /&gt;
......[RTS] - [YUP1,RConsole]&lt;BR /&gt;
......[SID] - [TYU3,2013-09-26,QConsole]&lt;BR /&gt;
......[DSW] - [GKFO,2013-10-29,iConsole,Payment3]&lt;BR /&gt;
......[EDS] - [EDC1,FConsole]&lt;/P&gt;

&lt;P&gt;In the square brackets [(Field1),(Field2),(Field3),(Field4)] some of the fields are optional, they come and go in some events.&lt;/P&gt;

&lt;P&gt;1st combination [(Field1),(Field3)]&lt;BR /&gt;
2nd combination [(Field1),(Field2),(Field3)]&lt;BR /&gt;
3rd combination [(Field1),(Field2),(Field3),(Field4)] &lt;BR /&gt;
This means Field1 &amp;amp; Field3 are always there in the events but Field2 &amp;amp; Field4 are optional, I want to extract all of them.&lt;/P&gt;

&lt;P&gt;This is the regex which i have come up with, But seems like it is not working for my case&lt;/P&gt;

&lt;P&gt;rex field=_raw "\] - \[(?&amp;lt; Field1 &amp;gt;[^,]+)(,)?(?&amp;lt; Field2 &amp;gt;[^,]+)?,(?&amp;lt; Field3 &amp;gt;[^,\]]+)(,)?(&amp;lt; Field4 &amp;gt;[^\]]+)?" &lt;BR /&gt;
PS- I have added a space between "&amp;lt;" and "&amp;gt;" because it text box was escaping it.&lt;BR /&gt;
Any help would be really appreciated&lt;/P&gt;

&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2013 15:38:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144525#M12694</guid>
      <dc:creator>luv</dc:creator>
      <dc:date>2013-11-15T15:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144526#M12695</link>
      <description>&lt;P&gt;You said:  This means Field1 &amp;amp; Field3 are always there in the events but Field3 &amp;amp; Field4 are optional, I want to extract all of them.&lt;/P&gt;

&lt;P&gt;Did you mean Field2 &amp;amp; Field4 are optional?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2013 15:46:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144526#M12695</guid>
      <dc:creator>dmaislin_splunk</dc:creator>
      <dc:date>2013-11-15T15:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144527#M12696</link>
      <description>&lt;P&gt;You can use following. Assumption there are atleast 2 fields and they are separated by comma. You can add more eval statements if you have more fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;..your search..| rex field=_raw ".*\[(?&amp;lt;fieldlist&amp;gt;[^\]]+)" |eval fieldlist=split(fieldlist,",") 
| eval fieldcount=mvcount(fieldlist) 
| eval field1=mvindex(fieldlist,0) 
| eval field2=case(fieldcount &amp;gt; 2,mvindex(fieldlist,1),1=1,"")
| eval field3=case(fieldcount &amp;gt; 2,mvindex(fieldlist,2),1=1,mvindex(fieldlist,1))
| eval field4=case(fieldcount &amp;gt; 3,mvindex(fieldlist,3),1=1,"")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Nov 2013 16:01:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144527#M12696</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2013-11-15T16:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144528#M12697</link>
      <description>&lt;P&gt;I think this will also work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.+\[(?&amp;lt;FIELD1&amp;gt;[^,]+)\,?(?&amp;lt;FIELD2&amp;gt;[0-9-]+)?\,(?&amp;lt;FIELD3&amp;gt;\w+)\,?(?&amp;lt;FIELD4&amp;gt;\S+)?\]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Nov 2013 16:20:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144528#M12697</guid>
      <dc:creator>dmaislin_splunk</dc:creator>
      <dc:date>2013-11-15T16:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144529#M12698</link>
      <description>&lt;P&gt;that worked!!! thank you so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2013 19:52:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144529#M12698</guid>
      <dc:creator>luv</dc:creator>
      <dc:date>2013-11-15T19:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144530#M12699</link>
      <description>&lt;P&gt;This is really cool way to extract fields,it worked....Will definitely try more of this in future &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2013 19:54:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144530#M12699</guid>
      <dc:creator>luv</dc:creator>
      <dc:date>2013-11-15T19:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144531#M12700</link>
      <description>&lt;P&gt;Please accept this answer by checking the check mark.  Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2013 19:59:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144531#M12700</guid>
      <dc:creator>dmaislin_splunk</dc:creator>
      <dc:date>2013-11-15T19:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144532#M12701</link>
      <description>&lt;P&gt;Thanks much!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2013 20:22:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144532#M12701</guid>
      <dc:creator>dmaislin_splunk</dc:creator>
      <dc:date>2013-11-15T20:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144533#M12702</link>
      <description>&lt;P&gt;just out of curiosity whats this "\" for?? between ".+\[(?&lt;FIELD1&gt;[^,]+)" and ","&lt;BR /&gt;
same with "?(?&lt;FIELD2&gt;[0-9-]+)?" and ","&lt;BR /&gt;
is there something which needs to be escaped?&lt;/FIELD2&gt;&lt;/FIELD1&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2013 20:47:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144533#M12702</guid>
      <dc:creator>luv</dc:creator>
      <dc:date>2013-11-15T20:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144534#M12703</link>
      <description>&lt;P&gt;You probably don't need to escape the comma but it never hurts to be literal.  I should have just escaped the last one too.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2013 20:56:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144534#M12703</guid>
      <dc:creator>dmaislin_splunk</dc:creator>
      <dc:date>2013-11-15T20:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to extract optional fields in splunk through regex</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144535#M12704</link>
      <description>&lt;P&gt;Hi I have events look like this:&lt;/P&gt;

&lt;P&gt;DISKBSIZE,T0001,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0&lt;BR /&gt;
DISKBSIZE,T3729,8.0,4.0,0.0,7.4,4.0,4.0,4.0,0.0,10.8,0.0,0.0,6.0,0.0,4.0,6.0,0.0,10.5,0.0,8.0,4.0,4.0,0.0,8.7,4.0,8.4,5.7,4.0,9.3,0.0,5.5,0.0&lt;BR /&gt;
DISKBSIZE,T3728,10.2,4.0,0.0,0.0,5.7,27.8,5.7,8.6&lt;BR /&gt;
DISKBSIZE,T3729,0.0,4.0,11.3,0.0,0.0,10.8,0.0,6.0,0.0,5.3,4.0,0.0,11.1,0.0,4.0,6.0,0.0,5.6,0.0,13.9,0.0,4.0,5.3,17.1,0.0,9.3,0.0,10.0,5.4,6.7,4.0,13.2,0.0,8.0,0.0&lt;/P&gt;

&lt;P&gt;Some fields come and go.Need a regex which extracts multiple fields.&lt;BR /&gt;
Here is the regex which i came up with &lt;/P&gt;

&lt;P&gt;|rex field=_raw "(?i)DISKBSIZE,(?P[^,]&lt;EM&gt;),(?P[^,]&lt;/EM&gt;\d+),(?P[^,]&lt;EM&gt;\d+),(?P[^,]&lt;/EM&gt;\d+),(?P[^,]&lt;EM&gt;\d+),(?P[^,]&lt;/EM&gt;\d+),(?P[^,]&lt;EM&gt;\d+),(?P[^,]&lt;/EM&gt;\d+),(?P[^,]&lt;EM&gt;\d+),(?P[^,]&lt;/EM&gt;\d+),?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?,?(?P[^,]&lt;EM&gt;\d+)?,?(?P[^,]&lt;/EM&gt;\d+)?"&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 19:52:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Unable-to-extract-optional-fields-in-splunk-through-regex/m-p/144535#M12704</guid>
      <dc:creator>d29priyanka</dc:creator>
      <dc:date>2015-04-07T19:52:13Z</dc:date>
    </item>
  </channel>
</rss>

