<?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 a field into more fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342804#M101547</link>
    <description>&lt;P&gt;The employee identifier will only be either User: &lt;A href="mailto:someone@company.com"&gt;someone@company.com&lt;/A&gt; or User: company-9\1234 and I am only concerned with "someone" or "1234" respectively. &lt;/P&gt;

&lt;P&gt;I am not sure about the format of your rex expressions, perhaps you wrote them in the free regex101 editor.   But my do work in the Search App.&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jun 2017 20:31:16 GMT</pubDate>
    <dc:creator>packet_hunter</dc:creator>
    <dc:date>2017-06-12T20:31:16Z</dc:date>
    <item>
      <title>Regex a field into more fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342800#M101543</link>
      <description>&lt;P&gt;For some reason the builtin field extractor is not working for me, and I am unable to successful create a .conf stanza to parse out some needed fields from ADFS logs.  So I have an extracted field called Message that contains all the information to create the new fields I need.&lt;/P&gt;

&lt;P&gt;Sample events are:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;The following user account has been locked out due to too many bad password attempts. Additional Data Activity ID: 00000000-0000-0000-0000-000000000000 User: someone@ibm.com Client IP: 129.42.38.7,192.168.2.13 nBad Password Count: 6 nLast Bad Password Attempt: 1/8/2017 

The following user account has been locked out due to too many bad password attempts. Additional Data Activity ID: 00000000-0000-0000-0000-000000000000 User: ibm-9\1234 Client IP: 192.168.2.13 nBad Password Count: 6 nLast Bad Password Attempt: 1/9/2017 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The two events are similar except for User value and Client IP&lt;/P&gt;

&lt;P&gt;What I would like to do is rex out all the information into&lt;/P&gt;

&lt;P&gt;Msg = The following user account has been locked out due to too many bad password attempts.&lt;BR /&gt;
Activity_ID= 00000000-0000-0000-0000-000000000000&lt;BR /&gt;
Employee= someone &lt;BR /&gt;
OR &lt;BR /&gt;
Employee= 1234&lt;BR /&gt;
Client_IP= 129.42.38.7,192.168.2.13&lt;BR /&gt;
OR &lt;BR /&gt;
Client_IP=192.168.2.13&lt;BR /&gt;
Bad_Password_Count = 6&lt;BR /&gt;
Last_Bad_Password = 1/8/2017&lt;/P&gt;

&lt;P&gt;Here is my initial query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=wineventlog sourcetype="WinEventLog:Security"  EventCode=516 | rex field=Message "(?&amp;lt;Employee&amp;gt;.+)@" | rex field=Message "(?&amp;lt;Msg&amp;gt;.+)." |table  Msg Employee _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As you can I am using an already extracted field, to get Msg and Employee.   I just need a regex Ninja to show me how to slice this up.&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;

&lt;P&gt;BTW why do expressions in regex101 editor not work in the search app (and vice versa)??  Is there a tutorial on the differences?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:25:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342800#M101543</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2020-09-29T14:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Regex a field into more fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342801#M101544</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| rex "^(?&amp;lt;Msg&amp;gt;.+?)\s+Additional Data" 
| rex "Activity ID:\s+(?&amp;lt;Activity_ID&amp;gt;[-0-9]+)\s" 
| rex "User:\s+(?&amp;lt;Employee&amp;gt;.+?)\s+Client IP:\s+(?&amp;lt;Client_IP&amp;gt;[\.0-9,\s]+?)\s+nBad")
| rex field=Employee "^(?&amp;lt;Employee&amp;gt;.+)@" 
| rex field=Employee "\\(?&amp;lt;Employee&amp;gt;.+)$" 
| rex "Bad Password Count:\s+(?&amp;lt;Bad_Password_Count&amp;gt;\d+)" 
| rex "Last Bad Password Attempt:\s+(?&amp;lt;Last_Bad_Password&amp;gt;[0-9\\]+)" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To answer your questions about splunk vs regex101, it takes a bit of getting used to what to escape.  In general, you are NOT escaping everything in regex101 that you need to escape in splunk.  &lt;/P&gt;

&lt;P&gt;So, as you can see above, I don't try to do everything in one pass, I break the whole message up into reasonable chunks. That is because if any one part of a regex fails it all fails, so I'd rather keep it local.&lt;/P&gt;

&lt;P&gt;I don't assume that there will always be only one space after the colon in the data, so that's why I have &lt;CODE&gt;\s+&lt;/CODE&gt; in various spots.  &lt;/P&gt;

&lt;P&gt;When pulling a chunk of data, if I know the data type well enough to make a list of what are valid characters, then I will do so, so that the regular expression can slurp them up and stop when it gets to the invalid ones.  For example, Client_IP should consist of 0-9, period, comma, and maybe an occasional space if it came in with a space after the comma.  I put a question mark after the plus so that it will be lazy; if the regex encounters a space that isn't part of the IP section, then the space will be left to the chunk after it.    &lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 22:14:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342801#M101544</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-09T22:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Regex a field into more fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342802#M101545</link>
      <description>&lt;P&gt;Thank you for the responses.  I appreciate your explanation of regex101 and the rex examples.&lt;BR /&gt;
Just fyi, I had to rework some of the rex expressions but your examples helped me trigger some memories.&lt;BR /&gt;
Here is what I finally came up with if anyone is interested.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=wineventlog 

sourcetype="WinEventLog:Security"  

EventCode=516 

| rex field=Message "(?&amp;lt;employee&amp;gt;.+)@" 

|rex field=Message "\\\\(?&amp;lt;employee&amp;gt;.+)"

| rex field=Message "^(?&amp;lt;Msg&amp;gt;.+)"

| rex field=Message "Activity ID:\s+(?&amp;lt;Activity_ID&amp;gt;[-0-9]+)\s" 

| rex field=Message "Bad Password Count:\s+(?&amp;lt;Bad_Pswd_Count&amp;gt;\d+)"

| rex field=Message "Last Bad Password Attempt:\s+(?&amp;lt;Last_Bad_Pswd&amp;gt;[0-9\\\\].+)" 

|rex field=Message "Client IP:\s+(?&amp;lt;Client_IP&amp;gt;[\.0-9,\s]+?)\s+nBad" 

|table employee Msg Activity_ID Bad_Pswd_Count Last_Bad_Pswd Client_IP
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Jun 2017 15:18:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342802#M101545</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2017-06-12T15:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Regex a field into more fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342803#M101546</link>
      <description>&lt;P&gt;Your &lt;CODE&gt;&amp;lt;employee&amp;gt;&lt;/CODE&gt; lines both presume that there will only ever be an @ or a  \ in that field, never anywhere else.  Is that a valid assumption?   Also, no, those won't work.  It looks like the @ version will end up reading back to the beginning, since a period will match all the characters, and the \ version will read to the end for the same reason.   &lt;/P&gt;

&lt;P&gt;Try these:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex field=Message "User:\s+(?[^@]+)@" 
 | rex field=Message "User:[^\\]*\\\\(?\S+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your &lt;CODE&gt;&amp;lt;msg&amp;gt;&lt;/CODE&gt; line will eat up the entire message until a "carriage return" or end of file.  Okay?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 20:18:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342803#M101546</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-12T20:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Regex a field into more fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342804#M101547</link>
      <description>&lt;P&gt;The employee identifier will only be either User: &lt;A href="mailto:someone@company.com"&gt;someone@company.com&lt;/A&gt; or User: company-9\1234 and I am only concerned with "someone" or "1234" respectively. &lt;/P&gt;

&lt;P&gt;I am not sure about the format of your rex expressions, perhaps you wrote them in the free regex101 editor.   But my do work in the Search App.&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 20:31:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-a-field-into-more-fields/m-p/342804#M101547</guid>
      <dc:creator>packet_hunter</dc:creator>
      <dc:date>2017-06-12T20:31:16Z</dc:date>
    </item>
  </channel>
</rss>

