# Distinguishing username from domain\\username using grok

**URL:** <https://discuss.elastic.co/t/distinguishing-username-from-domain-username-using-grok/294988>\
**Category:** Logstash\
**Created:** [January 20, 2022, 7:20pm UTC](https://discuss.elastic.co/t/distinguishing-username-from-domain-username-using-grok/294988 "2022-01-20T19:20:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smithtod](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@smithtod](https://discuss.elastic.co/u/smithtod)\
**Post date:** [January 20, 2022, 7:20pm UTC](https://discuss.elastic.co/t/distinguishing-username-from-domain-username-using-grok/294988/1 "2022-01-20T19:20:23Z")

</div>

I am trying to create a grok statement that will pull the username out of a syslog file. When users enter their authentication information for our VPN login, they can put either domain\username, or just username, and either will work. However, I am having an issue trying to capture just the username using a grok statement. Below is my grok statement:  
**%{SYSLOGPROG:syslog\_pri} %{TIMESTAMP\_ISO8601} %{SYSLOGHOST:@hostname} PulseSecure: - - - %{TIMESTAMP\_ISO8601} - %{HOSTNAME:NetworkDeviceName} - [%{IPV4:source\_ip\_address}]( | domain\)%{USERNAME:user}%{GREEDYDATA:syslog\_message}**  
However, it always just captures the domain name as the username. Am I using the correct regex for instances where there can be either a space, then username, or space, domain\username, after the IP address?  
Edit: when I posted this here, it does not show the escape backslash after the domain name, but it is there in my grok statement.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 20, 2022, 10:06pm UTC](https://discuss.elastic.co/t/distinguishing-username-from-domain-username-using-grok/294988/2 "2022-01-20T22:06:19Z")

</div>

> [@smithtod](#):
>
> [%{IPV4:source\_ip\_address}]( | domain)%{USERNAME:user}

Rather than using alternation I would use ? (zero or more) around the domain

```
%{IPV4:source_ip_address}] (domain\)?%{USERNAME:user}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 17, 2022, 10:06pm UTC](https://discuss.elastic.co/t/distinguishing-username-from-domain-username-using-grok/294988/3 "2022-02-17T22:06:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
