<?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 extracts fields differently in props than same regex used in SPL REX command in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Why-does-regex-extract-fields-differently-in-props-than-same/m-p/618722#M106739</link>
    <description>&lt;P&gt;I believe it's a matter of whether a newline is present or not.&amp;nbsp; At search time, there will be a newline.&amp;nbsp; There will not be one for single-line events, but it doesn't matter in that case.&amp;nbsp; At index time, newlines are stripped before regex processing so the behavior is different.&lt;/P&gt;&lt;P&gt;I think it problem can be avoided with a slightly different regex.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;] (?&amp;lt;questiontype&amp;gt;\w+)\s+(?&amp;lt;questionname&amp;gt;\S*)&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 28 Oct 2022 12:51:35 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2022-10-28T12:51:35Z</dc:date>
    <item>
      <title>Why does regex extract fields differently in props than same regex used in SPL REX command?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-does-regex-extract-fields-differently-in-props-than-same/m-p/618679#M106736</link>
      <description>&lt;P&gt;Hi Splunkers.&lt;/P&gt;
&lt;P&gt;I'm trying to extract fields from Windows DNS debug logs but running into extraction issues for some events.&lt;/P&gt;
&lt;P&gt;Most events the fields extract o.k.&lt;BR /&gt;I'm finding for some events, the regex is returning more than it should in the field.&lt;BR /&gt;i.e. returns the field plus the remaining text in the raw event.&lt;/P&gt;
&lt;P&gt;Works for most events extracting the domain correctly as, for example.&amp;nbsp;&lt;STRONG&gt;(3)web(4)site(5)again(3)net(0)&lt;/STRONG&gt; but when it fails, it extracts the questionname filed as &lt;STRONG&gt;(3)web(4)site(5)again(3)net(0)&lt;/STRONG&gt;&amp;nbsp;plus the remaining text to the end of the event.&lt;/P&gt;
&lt;P&gt;Regex in use is straight out of the Splunk TA for Windows from props.conf:&lt;BR /&gt;&lt;BR /&gt;] (?&amp;lt;questiontype&amp;gt;\w+)\s+(?&amp;lt;questionname&amp;gt;.*)&lt;/P&gt;
&lt;P&gt;Sample data:&lt;/P&gt;
&lt;P&gt;-------&lt;BR /&gt;28/10/2022 12:29:22 PM 07AC PACKET 1234523DDF690A11 UDP Snd 10.20.222.111 54c5 R Q [8081 DR NOERROR] A (3)web(4)site(5)again(3)net(0)&lt;BR /&gt;UDP response info at 1234523DDF690A11&lt;BR /&gt;Socket = 736&lt;BR /&gt;Remote addr 10.20.222.111, port 62754&lt;BR /&gt;Time Query=20130697, Queued=0, Expire=0&lt;BR /&gt;Buf length = 0x0200 (512)&lt;BR /&gt;Msg length = 0x0054 (84)&lt;BR /&gt;Message:&lt;BR /&gt;XID 0x54c5&lt;BR /&gt;Flags 0x8180&lt;BR /&gt;QR 1 (RESPONSE)&lt;BR /&gt;OPCODE 0 (QUERY)&lt;BR /&gt;AA 0&lt;BR /&gt;TC 0&lt;BR /&gt;RD 1&lt;BR /&gt;RA 1&lt;BR /&gt;Z 0&lt;BR /&gt;CD 0&lt;BR /&gt;AD 0&lt;BR /&gt;RCODE 0 (NOERROR)&lt;BR /&gt;QCOUNT 1&lt;BR /&gt;ACOUNT 2&lt;BR /&gt;NSCOUNT 0&lt;BR /&gt;ARCOUNT 0&lt;BR /&gt;QUESTION SECTION:&lt;BR /&gt;[snipped for brevity]&lt;/P&gt;
&lt;P&gt;--------&lt;/P&gt;
&lt;P&gt;If I use the regex from the props.conf above in a REX command via SPL, the field is extracted correctly.&lt;BR /&gt;The same regex also works fine in regex101 etc. (with the same event causes the issue used as test data)&lt;/P&gt;
&lt;P&gt;Can anyone explain why the regex works differently when used in props.conf than in direct SPL, and where I should be looking?&lt;BR /&gt;As mentioned above, issue only occurs for some events.&amp;nbsp; Note that DNS events are both single line and multi-line, with only some multi-line having the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 14:27:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-does-regex-extract-fields-differently-in-props-than-same/m-p/618679#M106736</guid>
      <dc:creator>torowa</dc:creator>
      <dc:date>2022-10-28T14:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Regex extracts fields differently in props than same regex used in SPL REX command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-does-regex-extract-fields-differently-in-props-than-same/m-p/618722#M106739</link>
      <description>&lt;P&gt;I believe it's a matter of whether a newline is present or not.&amp;nbsp; At search time, there will be a newline.&amp;nbsp; There will not be one for single-line events, but it doesn't matter in that case.&amp;nbsp; At index time, newlines are stripped before regex processing so the behavior is different.&lt;/P&gt;&lt;P&gt;I think it problem can be avoided with a slightly different regex.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;] (?&amp;lt;questiontype&amp;gt;\w+)\s+(?&amp;lt;questionname&amp;gt;\S*)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 28 Oct 2022 12:51:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-does-regex-extract-fields-differently-in-props-than-same/m-p/618722#M106739</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-10-28T12:51:35Z</dc:date>
    </item>
  </channel>
</rss>

