<?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 Rex extraction specific example in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26411#M5087</link>
    <description>&lt;P&gt;Hello Splunkers,&lt;/P&gt;

&lt;P&gt;Problem: Splunk query returns events where "Account_Name" appears twice, thus returning multiple/inaccurate Account Name results.&lt;/P&gt;

&lt;P&gt;Solution: I want to rex grab the second instance of Account_Name. Here is an example of output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Message=An account was successfully logged on.

Subject:
Security ID:        S-1-0-0

Account Name:       -
Account Domain:     -
Logon ID:       0x0

Logon Type:         3

New Logon:
Security ID:        S-1-5-21-1616162011-3457912633-3195248547-20163

Account Name:       johndoe

Account Domain:     THISDOMAIN
Logon ID:       stuff_here
Logon GUID:     {00000000-0000-0000-0000-000000000000}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this situation, I want to grab "johndoe". I am not sure how to skip all of the lines in between the first Account Name and the second, then precede to pull "johndoe". &lt;/P&gt;

&lt;P&gt;Thanks for your answers and help in advance.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Aug 2012 15:54:18 GMT</pubDate>
    <dc:creator>cburr2012</dc:creator>
    <dc:date>2012-08-06T15:54:18Z</dc:date>
    <item>
      <title>Rex extraction specific example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26411#M5087</link>
      <description>&lt;P&gt;Hello Splunkers,&lt;/P&gt;

&lt;P&gt;Problem: Splunk query returns events where "Account_Name" appears twice, thus returning multiple/inaccurate Account Name results.&lt;/P&gt;

&lt;P&gt;Solution: I want to rex grab the second instance of Account_Name. Here is an example of output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Message=An account was successfully logged on.

Subject:
Security ID:        S-1-0-0

Account Name:       -
Account Domain:     -
Logon ID:       0x0

Logon Type:         3

New Logon:
Security ID:        S-1-5-21-1616162011-3457912633-3195248547-20163

Account Name:       johndoe

Account Domain:     THISDOMAIN
Logon ID:       stuff_here
Logon GUID:     {00000000-0000-0000-0000-000000000000}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this situation, I want to grab "johndoe". I am not sure how to skip all of the lines in between the first Account Name and the second, then precede to pull "johndoe". &lt;/P&gt;

&lt;P&gt;Thanks for your answers and help in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2012 15:54:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26411#M5087</guid>
      <dc:creator>cburr2012</dc:creator>
      <dc:date>2012-08-06T15:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rex extraction specific example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26412#M5088</link>
      <description>&lt;P&gt;You have a couple of options.&lt;/P&gt;

&lt;P&gt;One is to use a multi-line regular expression and define a capture group targeted at the &lt;EM&gt;second&lt;/EM&gt; occurrence of "Account Name:".&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "(?ms)Account Name:.*?Account Name:\s+(?&amp;lt;account_name&amp;gt;\S+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A different, perhaps more flexible way is to define a negative lookahead that will cause the regular expression not to match when "Account Name:" is followed by a hyphen.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "Account Name:\s+(?!-)(?&amp;lt;account_name&amp;gt;\S+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Aug 2012 16:16:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26412#M5088</guid>
      <dc:creator>hexx</dc:creator>
      <dc:date>2012-08-06T16:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Rex extraction specific example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26413#M5089</link>
      <description>&lt;P&gt;Perfect, hexx.&lt;/P&gt;

&lt;P&gt;Follow-up Question: Do you know of a good source for Splunk rexing? I don't have much experience with traditional regexing and am not familiar with the difference between the two, if any.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2012 16:20:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26413#M5089</guid>
      <dc:creator>cburr2012</dc:creator>
      <dc:date>2012-08-06T16:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Rex extraction specific example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26414#M5090</link>
      <description>&lt;P&gt;I am not sure what you mean by "Splunk rexing", but if what you are curious about is the flavor of regular expressions that Splunk uses, I can tell you that it's &lt;A href="http://www.regular-expressions.info/pcre.html"&gt;PCRE&lt;/A&gt;. If you want to know more about the syntax of the "rex" command and see examples, I would suggest to check &lt;A href="http://www.splunk.com/base/Documentation/5.0/SearchReference/Rex"&gt;this topic&lt;/A&gt; in the Search reference manual.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2012 16:23:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26414#M5090</guid>
      <dc:creator>hexx</dc:creator>
      <dc:date>2012-08-06T16:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Rex extraction specific example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26415#M5091</link>
      <description>&lt;P&gt;Yes, the flavor &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks again.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2012 16:27:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26415#M5091</guid>
      <dc:creator>cburr2012</dc:creator>
      <dc:date>2012-08-06T16:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Rex extraction specific example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26416#M5092</link>
      <description>&lt;P&gt;I know this has been answered long ago, but I'm surprised that no one has mentioned eval and mvindex yet. With a multi-value field, you can use mvindex to target the first, second (or third or fourth, etc.) value of a field with the same name.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... 
| eval subject_account=mvindex(Account_Name, 0) 
| eval target_account=mvindex(Account_Name, 1) 
| where target_account = "some_account"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some events also have an empty target account, in which case you can write an if statement into your eval. See this answer for an example.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://splunk-base.splunk.com/answers/48096/account_name-field-listing-in-events-4624-4768-and-4769-windows-2008"&gt;http://splunk-base.splunk.com/answers/48096/account_name-field-listing-in-events-4624-4768-and-4769-windows-2008&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For cases like Account_Name, I find the mvindex to be much easier to use than regular expressions.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2012 08:26:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Rex-extraction-specific-example/m-p/26416#M5092</guid>
      <dc:creator>tiny3001</dc:creator>
      <dc:date>2012-11-19T08:26:47Z</dc:date>
    </item>
  </channel>
</rss>

