<?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: trouble using regex to find a timestamp in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122968#M33194</link>
    <description>&lt;P&gt;Does Splunk parse the time in a nice way, i.e. is it "the same" time in Splunk as in the actual log message? In that case, you can access the time information through the built-in field &lt;CODE&gt;_time&lt;/CODE&gt; (which is &lt;CODE&gt;epoch&lt;/CODE&gt;), instead of doing an extra field extraction of the timestamp. &lt;/P&gt;

&lt;P&gt;If everything is basically OK with the timestamp parsing, then don't bother with the &lt;CODE&gt;TIME_FORMAT&lt;/CODE&gt;, and definitely not with the &lt;CODE&gt;TIME_PREFIX&lt;/CODE&gt;. Have a look at the &lt;CODE&gt;convert&lt;/CODE&gt; search command, or the &lt;CODE&gt;strftime()&lt;/CODE&gt; function of the &lt;CODE&gt;eval&lt;/CODE&gt; search command to understand on how to convert and use the information stored in &lt;CODE&gt;_time&lt;/CODE&gt;. Stop reading here.&lt;/P&gt;

&lt;P&gt;But if you mean that your events get the "wrong" time in Splunk, e.g. if there is more than one timestamp, then you need to write the correct &lt;CODE&gt;TIME_FORMAT&lt;/CODE&gt;, and also possibly the &lt;CODE&gt;TIME_PREFIX&lt;/CODE&gt; and &lt;CODE&gt;MAX_TIMESTAMP_LOOKAHEAD&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;TIME_FORMAT&lt;/CODE&gt; should reflect on how the timestamp is formatted in your event, e.g.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;%e for days 1-31.
%m for days 01-31.
%y for two-digit years.
%Y for four-digit years.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;TIME_PREFIX&lt;/CODE&gt; shall match upto where the time information is present in the event. If your messages are as static as your samples, that could be;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;TIME_PREFIX = (?:[^,]+,){5}&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;i.e. the time information is in the sixth element in a comma-separated list, so skipping over non-comma characters followed by a comma 5 times would get you there.&lt;/P&gt;

&lt;P&gt;Makes any sense?&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2013 21:21:27 GMT</pubDate>
    <dc:creator>kristian_kolb</dc:creator>
    <dc:date>2013-10-30T21:21:27Z</dc:date>
    <item>
      <title>trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122959#M33185</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to use regex to define where my stamp stamp is in the data below.  I have it working for some of the data but there are instances where it does not work, and I'm struggling to understand why... the data looks the same.&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;

&lt;P&gt;Regex: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;,(?=\d{1}/\d{2}/\d{4} \d{2}:\d{2})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;%m/%d/%Y %H:%M
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Works here:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;38112544113,mmehltretter@legendequities.com,gabriela.fuselli@lfd.com,38112,AML Wholesaler NMG Template,9/29/2013 19:30,...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Timestamp = 9/29/13 7:30:00.000 PM&lt;/P&gt;

&lt;P&gt;Does not work here:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;36277629151,arnold.cottrell@lfg.com,nicole.hartnett@lfg.com,36277,Welcome: Extended Leadership Team,8/16/2013 8:56,...,,,9/30/2013 23:00,
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;TimeStamp = 9/30/13 11:00:00.000 PM (picking up another time later in event string)&lt;BR /&gt;
OR Here:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;37866185650,dconoway@americanportfolios.com,gabriela.fuselli@lfd.com,37866,AML Wholesaler NMG Template,9/24/2013 7:39,....,,,9/30/2013 22:59,
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Timestamp = 9/30/13 10:59:00.000 PM (picking up another time later in event string)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 18:47:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122959#M33185</guid>
      <dc:creator>jgautreau</dc:creator>
      <dc:date>2013-10-30T18:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122960#M33186</link>
      <description>&lt;P&gt;Can you repost your regex as code?  Highlight and select the 101010 format button.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 18:53:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122960#M33186</guid>
      <dc:creator>lukejadamec</dc:creator>
      <dc:date>2013-10-30T18:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122961#M33187</link>
      <description>&lt;P&gt;Your regex expects only two-digit hours so the examples occurring before noon are not recognized.  &lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 18:54:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122961#M33187</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2013-10-30T18:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122962#M33188</link>
      <description>&lt;P&gt;Here is what I'd put into the props.conf if this were my data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TIME_PREFIX = TimeStamp = 
TIME_FORMAT = %m/%d/%Y %H:%M:5S.%3N %p
MAX_TIMESTAMP_LOOKAHEAD = 165
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But if you are wanting a field extraction for the date/time, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[sS]tamp\s+\=\s+(?&amp;lt;dateTime&amp;gt;\d+\/\d+\/\d+\s+\d+\:\d+\:\d+\.\d+\s+\w+)\s+
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You mention "picking up another time later in event string" but there is no way for any of us to know what impact that might have. Try one of these and let us know if it works. There may be a better answer if you provide us with more info.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 19:00:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122962#M33188</guid>
      <dc:creator>rgcurry</dc:creator>
      <dc:date>2013-10-30T19:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122963#M33189</link>
      <description>&lt;P&gt;,(?=d{1}/d{2}/d{4} d{2}:d{2})&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 19:10:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122963#M33189</guid>
      <dc:creator>jgautreau</dc:creator>
      <dc:date>2013-10-30T19:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122964#M33190</link>
      <description>&lt;P&gt;okay - got it!  thanks! JG&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 19:14:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122964#M33190</guid>
      <dc:creator>jgautreau</dc:creator>
      <dc:date>2013-10-30T19:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122965#M33191</link>
      <description>&lt;P&gt;got it - thanks Rich!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 19:15:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122965#M33191</guid>
      <dc:creator>jgautreau</dc:creator>
      <dc:date>2013-10-30T19:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122966#M33192</link>
      <description>&lt;P&gt;&lt;CODE&gt;,(?=\d{1,2}/\d{1,2}/\d{4} \d{1,2}:\d{1,2})&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 19:16:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122966#M33192</guid>
      <dc:creator>jgautreau</dc:creator>
      <dc:date>2013-10-30T19:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122967#M33193</link>
      <description>&lt;P&gt;Sorry, but I think the 'Timestamp=xx/yy/zz' part of the question is actually the timestamp as Splunk parses it, and NOT part of the event.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 20:48:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122967#M33193</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-10-30T20:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122968#M33194</link>
      <description>&lt;P&gt;Does Splunk parse the time in a nice way, i.e. is it "the same" time in Splunk as in the actual log message? In that case, you can access the time information through the built-in field &lt;CODE&gt;_time&lt;/CODE&gt; (which is &lt;CODE&gt;epoch&lt;/CODE&gt;), instead of doing an extra field extraction of the timestamp. &lt;/P&gt;

&lt;P&gt;If everything is basically OK with the timestamp parsing, then don't bother with the &lt;CODE&gt;TIME_FORMAT&lt;/CODE&gt;, and definitely not with the &lt;CODE&gt;TIME_PREFIX&lt;/CODE&gt;. Have a look at the &lt;CODE&gt;convert&lt;/CODE&gt; search command, or the &lt;CODE&gt;strftime()&lt;/CODE&gt; function of the &lt;CODE&gt;eval&lt;/CODE&gt; search command to understand on how to convert and use the information stored in &lt;CODE&gt;_time&lt;/CODE&gt;. Stop reading here.&lt;/P&gt;

&lt;P&gt;But if you mean that your events get the "wrong" time in Splunk, e.g. if there is more than one timestamp, then you need to write the correct &lt;CODE&gt;TIME_FORMAT&lt;/CODE&gt;, and also possibly the &lt;CODE&gt;TIME_PREFIX&lt;/CODE&gt; and &lt;CODE&gt;MAX_TIMESTAMP_LOOKAHEAD&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;TIME_FORMAT&lt;/CODE&gt; should reflect on how the timestamp is formatted in your event, e.g.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;%e for days 1-31.
%m for days 01-31.
%y for two-digit years.
%Y for four-digit years.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;TIME_PREFIX&lt;/CODE&gt; shall match upto where the time information is present in the event. If your messages are as static as your samples, that could be;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;TIME_PREFIX = (?:[^,]+,){5}&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;i.e. the time information is in the sixth element in a comma-separated list, so skipping over non-comma characters followed by a comma 5 times would get you there.&lt;/P&gt;

&lt;P&gt;Makes any sense?&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 21:21:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122968#M33194</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-10-30T21:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: trouble using regex to find a timestamp</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122969#M33195</link>
      <description>&lt;P&gt;something is weird with the formatting here...is there only a fixed amount of &lt;CODE&gt;code&lt;/CODE&gt; elements that can be put into a single post? fixed now.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2013 21:23:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trouble-using-regex-to-find-a-timestamp/m-p/122969#M33195</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-10-30T21:23:06Z</dc:date>
    </item>
  </channel>
</rss>

