<?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: Why does rex/regex return different results than field-extraction? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296120#M89341</link>
    <description>&lt;P&gt;Formatting the submission removed the leading spaces. There is actually a space before Account Name in the real logs. &lt;/P&gt;

&lt;P&gt;I just checked again. With a field extraction, I am getting a match, but the match includes from user1 to the end of the log. If I take the same expression and use the rex command in search, I get exactly what I want. &lt;/P&gt;</description>
    <pubDate>Fri, 17 Nov 2017 17:16:01 GMT</pubDate>
    <dc:creator>jared_anderson</dc:creator>
    <dc:date>2017-11-17T17:16:01Z</dc:date>
    <item>
      <title>Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296114#M89335</link>
      <description>&lt;P&gt;Data:&lt;BR /&gt;
Nov 16 12:50:51 172.23.0.29 Nov 16 12:50:51 dc01 Microsoft_Windows_security_auditing.[1688]: Domain\user1: Security Microsoft Windows security auditing.: [Success Audit] A user account was changed.&lt;BR /&gt;
Subject:&lt;BR /&gt;
 Security ID:  domain\value&lt;BR /&gt;
 Account Name:  value&lt;BR /&gt;
 Account Domain:  Domain&lt;BR /&gt;
 Logon ID:  0xA058EB26&lt;BR /&gt;
Target Account:&lt;BR /&gt;
 Security ID:  domain\user1&lt;BR /&gt;
 Account Name:  user1&lt;BR /&gt;
 Account Domain:  domain&lt;BR /&gt;
Changed Attributes:&lt;BR /&gt;
 SAM Account Name: -&lt;BR /&gt;
 Display Name:  -&lt;BR /&gt;
 User Principal Name: -&lt;BR /&gt;
 Home Directory:  -&lt;BR /&gt;
 Home Drive:  -&lt;BR /&gt;
 Script Path:  -&lt;BR /&gt;
 Profile Path:  -&lt;BR /&gt;
 User Workstations: -&lt;BR /&gt;
 Password Last Set: 11/16/2017 12:50:50 PM&lt;BR /&gt;
 Account Expires:  -&lt;BR /&gt;
 Primary Group ID: -&lt;BR /&gt;
 AllowedToDelegateTo: -&lt;BR /&gt;
 Old UAC Value:  -&lt;BR /&gt;
 New UAC Value:  -&lt;BR /&gt;
 User Account Control: -&lt;BR /&gt;
 User Parameters: -&lt;BR /&gt;
 SID History:  -&lt;BR /&gt;
 Logon Hours:  -&lt;BR /&gt;
Additional Information:&lt;BR /&gt;
 Privileges:  - (EventID 4738)&lt;/P&gt;

&lt;P&gt;Regex Expression: &lt;CODE&gt;Target Account:\n.+\n Account Name: (?&amp;lt;target_user&amp;gt;.+)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Question:&lt;BR /&gt;
When I run this regular expression using the rex command it only matches. "user1"&lt;/P&gt;

&lt;P&gt;When use this regex in a field extraction it matches everything from user1 to the end of the log. Why does this expression return different results depending on how it is used?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:53:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296114#M89335</guid>
      <dc:creator>jared_anderson</dc:creator>
      <dc:date>2020-09-29T16:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296115#M89336</link>
      <description>&lt;P&gt;It appears that your question needs some tweaking. Can you edit your question, or add a comment, and use the &lt;CODE&gt;101010&lt;/CODE&gt; button on the highlighted "code" to make sure that there are not going to be characters that are removed due to having the code be interpreted before being displayed. Right now the &lt;CODE&gt;Regex&lt;/CODE&gt; expression doesn't seem to be complete, so it is hard to give you help.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 21:35:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296115#M89336</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-11-16T21:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296116#M89337</link>
      <description>&lt;P&gt;Updated, thanks for the help.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 16:12:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296116#M89337</guid>
      <dc:creator>jared_anderson</dc:creator>
      <dc:date>2017-11-17T16:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296117#M89338</link>
      <description>&lt;P&gt;It's likely because there's line ending characters that you can't see (printed by MS) on some events, and then sometimes not on others. regex is VERY specific about things, even the ones you can't see. &lt;/P&gt;

&lt;P&gt;If you use a '.+' it's a lazy match, so just try to be more specific with your anchor characters. MS is not known for it's ease of matching in it's events. They are quite verbose. &lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 16:49:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296117#M89338</guid>
      <dc:creator>tmarlette</dc:creator>
      <dc:date>2017-11-17T16:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296118#M89339</link>
      <description>&lt;P&gt;I don't understand why it would act differently using the rex command vs an extracted field in the same log.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 16:54:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296118#M89339</guid>
      <dc:creator>jared_anderson</dc:creator>
      <dc:date>2017-11-17T16:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296119#M89340</link>
      <description>&lt;P&gt;I don't know if it is a typo, but your REGEX has an extra space before &lt;CODE&gt;Account&lt;/CODE&gt;. It should be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Target Account:\n.+\nAccount Name: (?&amp;lt;target_user&amp;gt;.+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Like I say, it may be just a typo, but it would not match as you have supplied it.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 16:58:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296119#M89340</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-11-17T16:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296120#M89341</link>
      <description>&lt;P&gt;Formatting the submission removed the leading spaces. There is actually a space before Account Name in the real logs. &lt;/P&gt;

&lt;P&gt;I just checked again. With a field extraction, I am getting a match, but the match includes from user1 to the end of the log. If I take the same expression and use the rex command in search, I get exactly what I want. &lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 17:16:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296120#M89341</guid>
      <dc:creator>jared_anderson</dc:creator>
      <dc:date>2017-11-17T17:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296121#M89342</link>
      <description>&lt;P&gt;Are you using the EXTRACT- in props.conf to do the extraction?  By default the multiline regex modifier is enabled when doing field extraction that way.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.0.0/Admin/Propsconf#Field_extraction_configuration"&gt;props.conf - field extraction&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 19:47:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296121#M89342</guid>
      <dc:creator>wenthold</dc:creator>
      <dc:date>2017-11-17T19:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why does rex/regex return different results than field-extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296122#M89343</link>
      <description>&lt;P&gt;@wenthold is correct - the field extraction engine is adding the ?ms flags to the start of the regex in your props.conf file.  This means that your regex is matching on the whole event as though it's a single line.  This can be seen in the documentation too:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf?utm_source=answers&amp;amp;utm_medium=in-answer&amp;amp;utm_term=props.conf&amp;amp;utm_campaign=refdoc#Field_extraction_configuration"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf?utm_source=answers&amp;amp;utm_medium=in-answer&amp;amp;utm_term=props.conf&amp;amp;utm_campaign=refdoc#Field_extraction_configuration&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If your aim is to only extract the target account, I'd recommend using something like the following regex, which will work in field extractions or in the rex command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?m)Target\sAccount:\n?(?:(?!Changed).+?)\n?Account\sName:\s(?&amp;lt;target_user&amp;gt;.+?)\n?Account
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will also block capture of the rest of the event if the field is empty or all on one line, which is what's happening for you at the moment.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 05:55:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-rex-regex-return-different-results-than-field/m-p/296122#M89343</guid>
      <dc:creator>mtulett_splunk</dc:creator>
      <dc:date>2017-11-21T05:55:09Z</dc:date>
    </item>
  </channel>
</rss>

