title: Regex to determine windows UPN
body: <p>Using regex with the following example string format I would like to achieve the following:</p>
  
  <p>user@domain.local</p>
  
  <p>I would like to create a regex expression to retrieve specific parts of the string using named groups. I have the following working for domains but not for usernames:</p>
  
  <pre><code>(?&lt;domain&gt;([a-z0-9]+\.)*[a-z0-9]+\.[a-z]+).*(?&lt;username&gt;.*|)
  </code></pre>
  
  <p><a href="https://regex101.com/r/nxL7my/3" rel="nofollow noreferrer">https://regex101.com/r/nxL7my/3</a></p>
  
  <p>My group for domain is populated but I don't understand why my group for username won't populate. Is it because the regex needs to return to the start of the string to find the last index of '@' and then select everything before it? (This is because a windows UPN logon could have an '@' symbol therefor this is a valid character).</p>
  
  <p>Any input is greatly appreciated.</p>