<?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: How to create a regex to return events with specific usernames in a field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410559#M118484</link>
    <description>&lt;P&gt;You don't need to use the regex command if the field extract already exists:&lt;/P&gt;

&lt;P&gt;root search jsmith OR AccountName=jsmith&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 17:34:45 GMT</pubDate>
    <dc:creator>the_wolverine</dc:creator>
    <dc:date>2018-06-27T17:34:45Z</dc:date>
    <item>
      <title>How to create a regex to return events with specific usernames in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410555#M118480</link>
      <description>&lt;P&gt;I am trying to create a search that returns only those events that have a specific username (or part of a username) in the Account Name field under Target Account. I have zero experience with regular expressions, but based on some other posts I was able to put together a regex that seems to locate the appropriate field (which I tested on regex101.com). However, I can't seem to get the search to work - I've tried three different variations, and all error out. One final note, I'm using "like" because in the final iteration of the search, I'll be looking for any username that contains a specific suffix, not just one specific account. Appreciate the help.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;WORKING REGEX&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?ms)Target Account:.*Security ID:.*Account Name:\s+(?&amp;lt;Account_Name&amp;gt;[^ ]*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;SAMPLE EVENT&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;6/25/2018 01:07:58 PM
LogName=Security
SourceName=Microsoft Windows security auditing.
EventCode=4723
EventType=0
Type=Information
ComputerName=SERVER.TRX.COM
TaskCategory=User Account Management
OpCode=Info
RecordNumber=329720657
Keywords=Audit Success
Message=An attempt was made to change an account's password.
Subject:
    Security ID:        TRX\jsmith
    Account Name:   jsmith
    Account TRX:        TRX
    Logon ID:       0x6368FECE
Target Account:
    Security ID:        TRX\jsmith
    Account Name:   jsmith
    Account TRX:        TRX
Additional Information:
    Privileges
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;SEARCH THAT WORKS&lt;/STRONG&gt; (But does not use the regular expression)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=4723 OR EventCode=4724 | where like (Account_Name,"jsmith")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;REGEX SEARCHES TRIED&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventCode=4723 OR EventCode=4724 | where like ((regex "(?ms)Target Account:.*Security ID:.*Account Name:\s+(?&amp;lt;Account_Name&amp;gt;[^ ]*)"),"jsmith")
EventCode=4723 OR EventCode=4724 | where like ((regex = "(?ms)Target Account:.*Security ID:.*Account Name:\s+(?&amp;lt;Account_Name&amp;gt;[^ ]*)"),"jsmith")
EventCode=4723 OR EventCode=4724 | where like ((regex = (?ms)Target Account:.*Security ID:.*Account Name:\s+(?&amp;lt;Account_Name&amp;gt;[^ ]*)),"jsmith")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jun 2018 19:08:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410555#M118480</guid>
      <dc:creator>adamfiore</dc:creator>
      <dc:date>2018-06-26T19:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to return events with specific usernames in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410556#M118481</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.1.1/SearchReference/Regex"&gt;https://docs.splunk.com/Documentation/Splunk/7.1.1/SearchReference/Regex&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... root search ... | regex AccountName=“Regex”
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or even this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... root search ... | rex “Target Account:.*Security ID:.*Account Name:\s+(?&amp;lt;Account_Name&amp;gt;[^ ]*)” | where Account_Name=jsmith
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jun 2018 19:47:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410556#M118481</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2018-06-26T19:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to return events with specific usernames in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410557#M118482</link>
      <description>&lt;P&gt;These look like winEventLog:Security. You should look into using the Splunk TA for windows and the out of the box sourcetypes that come with it to handle this type of data. Then your extractions will work automatically rather than having to write your own.&lt;/P&gt;

&lt;P&gt;In terms of running an inline regex what @jkat54 said is correct, just run your base search followed by &lt;CODE&gt;... | regex "(?ms)Target Account:.*Security ID:.*Account Name:\s+jsmith"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 20:42:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410557#M118482</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2018-06-26T20:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to return events with specific usernames in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410558#M118483</link>
      <description>&lt;P&gt;Thanks. That worked and I'll also look into TA for Windows.  Appreciate the help.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 17:19:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410558#M118483</guid>
      <dc:creator>adamfiore</dc:creator>
      <dc:date>2018-06-27T17:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a regex to return events with specific usernames in a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410559#M118484</link>
      <description>&lt;P&gt;You don't need to use the regex command if the field extract already exists:&lt;/P&gt;

&lt;P&gt;root search jsmith OR AccountName=jsmith&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 17:34:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-regex-to-return-events-with-specific-usernames/m-p/410559#M118484</guid>
      <dc:creator>the_wolverine</dc:creator>
      <dc:date>2018-06-27T17:34:45Z</dc:date>
    </item>
  </channel>
</rss>

