RegEx to get domain from domain\username. I tried this but it returns the entire string.
What am I doing incorrectly? the end result should be domain
Regex is quite the large hammer for such a tiny nail. Just use
string domain = str.SubString(0, str.IndexOf('\\'));
If you insist on using regular expressions then what you are doing wrong is that you are are not escaping the \ (I'm also not sure why the . is there) Try
However for such a simple problem you would be better served just using .IndexOf to find the \ and then .Substring to return everything before it.
Will give you domain\
Will give you domain
[^x] gives you everything but x and \ has to be escaped likeso \\.