<?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 Regex Field extraction question in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128756#M34964</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am trying to extract a field and I have an error in my REGEX.  The line looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;6/26/2014 13:00:10.866 | 18636 | Cmd:ALARMS device:REED31_13HLOALP_RD, status:2:FAILED: Unresolved message: ALARMS, user:OKCLOI.MSS, parms: | UisCmdRequestManagerImpl.cpp | 747 | nLOG_EXCEPTIONS
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to pull the 5th section out of the line.  The extracted data in this log example would be 747.  I have this REGEX in my field extraction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?i)^[^\|][^\|][^\|][^\|] (?P{FIELDNAME}\s\d+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What have I done wrong?  Is the data in the third piped section not available for an "any"?  Do I need to break down that section?  &lt;/P&gt;</description>
    <pubDate>Wed, 02 Jul 2014 19:00:56 GMT</pubDate>
    <dc:creator>Bliide</dc:creator>
    <dc:date>2014-07-02T19:00:56Z</dc:date>
    <item>
      <title>Regex Field extraction question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128756#M34964</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am trying to extract a field and I have an error in my REGEX.  The line looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;6/26/2014 13:00:10.866 | 18636 | Cmd:ALARMS device:REED31_13HLOALP_RD, status:2:FAILED: Unresolved message: ALARMS, user:OKCLOI.MSS, parms: | UisCmdRequestManagerImpl.cpp | 747 | nLOG_EXCEPTIONS
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to pull the 5th section out of the line.  The extracted data in this log example would be 747.  I have this REGEX in my field extraction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?i)^[^\|][^\|][^\|][^\|] (?P{FIELDNAME}\s\d+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What have I done wrong?  Is the data in the third piped section not available for an "any"?  Do I need to break down that section?  &lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2014 19:00:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128756#M34964</guid>
      <dc:creator>Bliide</dc:creator>
      <dc:date>2014-07-02T19:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Field extraction question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128757#M34965</link>
      <description>&lt;P&gt;This worked for me.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?:[\S\s]*|){4}\s(?&amp;lt;fieldname&amp;gt;\d+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Jul 2014 19:15:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128757#M34965</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2014-07-02T19:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Field extraction question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128758#M34966</link>
      <description>&lt;P&gt;There's an eval function that does this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval temp=split(_raw,"|") | eval FieldX=mvindex(temp,4)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first eval splits your _raw into a multivalue field split by the pipe symbol, the second then pulls out the 4th of those fields, calling it FieldX.&lt;/P&gt;

&lt;P&gt;Obviously, rename as desired.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2014 19:39:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128758#M34966</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2014-07-02T19:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Field extraction question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128759#M34967</link>
      <description>&lt;P&gt;There are a couple minor issues with the regex as writen:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;It doesn't account for how many times a character repeats.&lt;/LI&gt;
&lt;LI&gt;It doesn't look for both a pipe and a non-pipe character (it only looks for non-pipes)&lt;/LI&gt;
&lt;LI&gt;The value of fieldname will have a leading space based on the placement of &lt;CODE&gt;\s&lt;/CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I like richalloway's approach, but I'm not sure the &lt;CODE&gt;[\S\s]&lt;/CODE&gt; is quote what you want.  I believe that would be interpreted to be a character range that includes all non-spaces and all spaces (which pretty much includes everything, which could be written as simple "&lt;CODE&gt;.&lt;/CODE&gt;")  Also, this should be anchored to the beginning of the line (&lt;CODE&gt;^&lt;/CODE&gt;).&lt;/P&gt;

&lt;P&gt;Here's my suggestion:  (Modified from richalloway's answer)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^(?:[^|]+\|){4}\s*(?&amp;lt;fieldname&amp;gt;\d+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically this means, from the start of the line, look for one or more character that's not a pipe, followed by a single pipe.  (Repeat 4 times; thus putting us into field 5).  Skip over any whitespace characters, and capture the following digits into a field named "fieldname".&lt;/P&gt;

&lt;P&gt;Of course, delimiter based field extractions are also another option using props.conf and &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Admin/Transformsconf"&gt;transforms.conf&lt;/A&gt;.&lt;/P&gt;

&lt;HR /&gt;</description>
      <pubDate>Wed, 02 Jul 2014 19:45:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128759#M34967</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2014-07-02T19:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Field extraction question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128760#M34968</link>
      <description>&lt;P&gt;This worked great.  I did not get a chance to try out the first two suggestions.  When I looked at the answers these three were already posted so I of course took the one that referenced others.  My REGEX is weak and I thank you all very much for the answers.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jul 2014 00:27:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128760#M34968</guid>
      <dc:creator>Bliide</dc:creator>
      <dc:date>2014-07-03T00:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Regex Field extraction question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128761#M34969</link>
      <description>&lt;P&gt;Don't forget to mark your question resolved by selecting the check mark next to one of the answers.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jul 2014 13:49:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-Field-extraction-question/m-p/128761#M34969</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2014-07-03T13:49:55Z</dc:date>
    </item>
  </channel>
</rss>

