<?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 match \\ in regex to extract a value from a field in my data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200362#M58085</link>
    <description>&lt;P&gt;You need to escape BOTH slashes with an additional backslash.&lt;/P&gt;

&lt;P&gt;so the first escape would be &lt;CODE&gt;\\&lt;/CODE&gt; then the second escape would be &lt;CODE&gt;\\&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;UserDisplayName=".*\\\\(.*)"  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, you probably want to make sure its an optional group in case the basic version shows up: &lt;A href="https://regex101.com/r/fA4tO1/3"&gt;https://regex101.com/r/fA4tO1/3&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "UserDisplayName=(?:.*\\\\)?(?&amp;lt;username&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 26 Oct 2015 18:51:07 GMT</pubDate>
    <dc:creator>aljohnson_splun</dc:creator>
    <dc:date>2015-10-26T18:51:07Z</dc:date>
    <item>
      <title>How to match \\ in regex to extract a value from a field in my data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200361#M58084</link>
      <description>&lt;P&gt;I have logs that have the following two formats&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1. Oct 26 13:22:55 1.2.3.4 1 2015-10-26T13:22:51.480-04:00 Device.domain.tld View - 2020 [View@6876 Severity="AUDIT_SUCCESS" Module="Admin" EventType="ADMIN_USERLOGGEDIN" UserSID="xxxxxxxxxxxxxxxxx" UserDisplayName="DOMAIN\\user1"] User DOMAIN\user1 has logged in to View Administrator
2. Oct 26 12:31:39 1.2.3.4 1 2015-10-26T12:31:31.351-04:00 Host.domain.tld View - 1007 [View@6876 Severity="INFO" Module="Agent" EventType="AGENT_CONNECTED" UserSID="yyyyyyyyyyyyyyyyy" UserDisplayName="DOMAIN\\user2" DesktopId="remote_access" PoolId="remote_access" MachineId="zzzzzzzzzzzzzzzzzzzzz" MachineName="hostname" MachineDnsName="host.domain.tld"] User DOMAIN\user2 has logged in to a new session on machine hostname
3. Oct 26 12:30:52 1.2.3.4 1 2015-10-26T12:30:51.331-04:00 Device.domain.tld View - 150 [View@6876 Severity="AUDIT_FAIL" Module="Broker" EventType="BROKER_USER_AUTHFAILED_SECUREID_ACCESS_DENIED" UserDisplayName="user2"] SecurID access denied for user user2
4. Oct 26 12:31:18 1.2.3.4 1 2015-10-26T12:31:15.882-04:00 host.domain.tld View - 1003 [View@6876 Severity="INFO" Module="Agent" EventType="AGENT_PENDING" UserSID="xxxxxxxxxxxxxxxxx" UserDisplayName="DOMAIN\\user2" DesktopId="remote_access" PoolId="remote_access" MachineId="zzzzzzzzzzzzzzzzzzzzz" MachineName="hostname" MachineDnsName="host.domain.tld"] The agent running on machine hostname has accepted an allocated session for user DOMAIN\user2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to capture the username into a field called &lt;STRONG&gt;user&lt;/STRONG&gt;.  This would be the username part of the &lt;STRONG&gt;UserDisplayName&lt;/STRONG&gt; field, but this shows up two different ways.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;UserDisplayName="DOMAIN\\username" 
UserDisplayName="username"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Inside a regex tester, I got the following syntax to work:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;UserDisplayName=".*\\(.*)"  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And that gives me the right group.  But when I tried converting that to splunk, I used:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=_raw "UserDisplayName=.*\\\(?&amp;lt;user&amp;gt;.*)" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gave me the following:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;user:  user1 has logged in to View Administrator&lt;/LI&gt;
&lt;LI&gt;user:  user2 has logged in to a new session on machine hostname&lt;/LI&gt;
&lt;LI&gt;user:&lt;/LI&gt;
&lt;LI&gt;user:  user2
So anything involving &lt;CODE&gt;\\&lt;/CODE&gt; seems to be problematic.&lt;BR /&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I figure once I get the syntax for each variable, I can use coalesce to get one overall label.  But I'm not sure how to go about this.&lt;/P&gt;

&lt;P&gt;Suggestions? &lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 18:44:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200361#M58084</guid>
      <dc:creator>reswob4</dc:creator>
      <dc:date>2015-10-26T18:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to match \\ in regex to extract a value from a field in my data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200362#M58085</link>
      <description>&lt;P&gt;You need to escape BOTH slashes with an additional backslash.&lt;/P&gt;

&lt;P&gt;so the first escape would be &lt;CODE&gt;\\&lt;/CODE&gt; then the second escape would be &lt;CODE&gt;\\&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;UserDisplayName=".*\\\\(.*)"  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, you probably want to make sure its an optional group in case the basic version shows up: &lt;A href="https://regex101.com/r/fA4tO1/3"&gt;https://regex101.com/r/fA4tO1/3&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "UserDisplayName=(?:.*\\\\)?(?&amp;lt;username&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Oct 2015 18:51:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200362#M58085</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2015-10-26T18:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to match \\ in regex to extract a value from a field in my data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200363#M58086</link>
      <description>&lt;P&gt;Hmm.. Tried that and it's weird.  I wonder if something is wrong with my overall config.&lt;/P&gt;

&lt;P&gt;I get the same results if I use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex  "\\\(?&amp;lt;user&amp;gt;.*?) "  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex  "\\\\(?&amp;lt;user&amp;gt;.*?) "
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;they both give me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;user:  \username"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I'm not sure why I'm getting the leading slash and why I'm getting the trailing quotes&lt;/P&gt;

&lt;P&gt;I'm continuing to try different things...&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 19:32:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200363#M58086</guid>
      <dc:creator>reswob4</dc:creator>
      <dc:date>2015-10-26T19:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to match \\ in regex to extract a value from a field in my data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200364#M58087</link>
      <description>&lt;P&gt;OK, here's what I got to work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; rex field=_raw "UserDisplayName=(?&amp;lt;user&amp;gt;.*?) " | eval user1=rtrim(user,"]") | eval user2=trim(user1,"\"") | eval user3=ltrim(user2,"DOMAIN\\") | rename user4 AS user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this gives me:&lt;/P&gt;

&lt;P&gt;user:  username&lt;/P&gt;

&lt;P&gt;Note:  the first rex command does NOT work if you use &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=_raw "UserDisplayName=(?&amp;lt;username&amp;gt;.*?) "
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you have to have user in there, not username or something else.  &lt;/P&gt;

&lt;P&gt;I'm marking the other answer as correct because that directly answered my question, even if it wasn't the method I used to get what I needed.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 20:35:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-match-in-regex-to-extract-a-value-from-a-field-in-my-data/m-p/200364#M58087</guid>
      <dc:creator>reswob4</dc:creator>
      <dc:date>2015-10-26T20:35:30Z</dc:date>
    </item>
  </channel>
</rss>

