<?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 not extracting fields with spaces between fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122642#M33072</link>
    <description>&lt;P&gt;This should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;date_time&amp;gt;\d{2}(?:\d{2}.)*\d{3})\s\[Logger\]\s\[(?&amp;lt;transaction_id&amp;gt;[^\]]+)\]\:\s+INFO\:\s+\[(?&amp;lt;info&amp;gt;[^\]]+)\]\s+PC\sResponse\:\s+RequestId\:\s+(?&amp;lt;request_id&amp;gt;[\S]+)\sUser\-Id\:\s+(?&amp;lt;user_id&amp;gt;[\S]+)\s+RequestType\:\s+Open
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some generally good ideas: Use tools to help you out, such as regex101.com - with their help, you don't need to poke around blindfolded and regular expressions become a fun thing. Furthermore, always escape special characters. Even if the tools may work without an escaped &lt;CODE&gt;:&lt;/CODE&gt;, splunk is quite strict with that. Lastly, in your capturing groups you used&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[^;]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to capure digits and other characters - I'd recommend you always use a negation of what comes &lt;EM&gt;before&lt;/EM&gt; the next field, which is why I used \S for those fields that are separated by a whitespace and&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[^\]]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;for those fields which were in square brackets. If you want to have the square brackets in your fields, then simply change those parts so that they also use the above method.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jul 2015 08:59:01 GMT</pubDate>
    <dc:creator>jeffland</dc:creator>
    <dc:date>2015-07-15T08:59:01Z</dc:date>
    <item>
      <title>Regex not extracting fields with spaces between fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122640#M33070</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;i am again struggling with regex.&lt;BR /&gt;
I have the following lines in a log file, some of the text is constantly in the log file so i thought that i would be able to keep it, i think my issue is with the gaps between the text, i am using /s+ to cope with whitespaces and possible tabs. I would like to extract the alpha-numeric strings.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2015/07/14 14:06:27.572 [Logger] [qtp1455736317-371]:  INFO: [55a51763e4b0a933] PC Response: RequestId: 150316 User-Id: 04-7FFABFFF-00809F1D RequestType: Open
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and i have tried to write the regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;date_time&amp;gt;\d{4}\.\d{2}\.\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3})\s+[Logger]\s+(?&amp;lt;transaction_id&amp;gt;[^;]+)\s+INFO:\s+(?&amp;lt;info&amp;gt;[^;]+)\s+PC\s+Response:\s+RequestId:\s+(?&amp;lt;request_id&amp;gt;[^;]+)\s+ User-Id:\s+(?&amp;lt;user_id&amp;gt;[^;]+)\s+RequestType:\s+Open
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;none of the fields are picked up, i do not know if its because there are : in the text and they need to be escaped..&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 08:35:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122640#M33070</guid>
      <dc:creator>ssaenger</dc:creator>
      <dc:date>2015-07-15T08:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Regex not extracting fields with spaces between fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122641#M33071</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;date_time&amp;gt;\d{4}/\d{2}/\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3})\s+[Logger]\s+(?&amp;lt;transaction_id&amp;gt;[^;]+)\s+INFO:\s+(?&amp;lt;info&amp;gt;[^;]+)\s+PC\s+Response:\s+RequestId:\s+(?&amp;lt;request_id&amp;gt;[^;]+)\s+User-Id:\s+(?&amp;lt;user_id&amp;gt;[^;]+)\s+RequestType:\s+Open
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your date_time has (slash). which matches only a dot, while your event has /. You also have a space before User-Id, while the \s+ means that there must be a second white space character there.&lt;/P&gt;

&lt;P&gt;I think you got all the other s+ correct. I'm not sure why you are matching everything except sem-colons ([^;]) but it should still work.  &lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 08:53:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122641#M33071</guid>
      <dc:creator>sduff_splunk</dc:creator>
      <dc:date>2015-07-15T08:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Regex not extracting fields with spaces between fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122642#M33072</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;date_time&amp;gt;\d{2}(?:\d{2}.)*\d{3})\s\[Logger\]\s\[(?&amp;lt;transaction_id&amp;gt;[^\]]+)\]\:\s+INFO\:\s+\[(?&amp;lt;info&amp;gt;[^\]]+)\]\s+PC\sResponse\:\s+RequestId\:\s+(?&amp;lt;request_id&amp;gt;[\S]+)\sUser\-Id\:\s+(?&amp;lt;user_id&amp;gt;[\S]+)\s+RequestType\:\s+Open
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some generally good ideas: Use tools to help you out, such as regex101.com - with their help, you don't need to poke around blindfolded and regular expressions become a fun thing. Furthermore, always escape special characters. Even if the tools may work without an escaped &lt;CODE&gt;:&lt;/CODE&gt;, splunk is quite strict with that. Lastly, in your capturing groups you used&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[^;]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to capure digits and other characters - I'd recommend you always use a negation of what comes &lt;EM&gt;before&lt;/EM&gt; the next field, which is why I used \S for those fields that are separated by a whitespace and&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[^\]]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;for those fields which were in square brackets. If you want to have the square brackets in your fields, then simply change those parts so that they also use the above method.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 08:59:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122642#M33072</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-07-15T08:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: Regex not extracting fields with spaces between fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122643#M33073</link>
      <description>&lt;P&gt;works a treat, thanks jeffland&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 11:07:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-not-extracting-fields-with-spaces-between-fields/m-p/122643#M33073</guid>
      <dc:creator>ssaenger</dc:creator>
      <dc:date>2015-07-15T11:07:15Z</dc:date>
    </item>
  </channel>
</rss>

