Reputation: 5712
var hostName = "tenant1.example.be";
var match = Regex.Match(hostName, @"([A-Za-z0-9]+)\.example\.be$", RegexOptions.IgnoreCase);
var subdomain = match.Success ? match.Value : null;
Result for subdomain is always: tenant1.example.be
instead of just tenant1
.
Anyone?
Upvotes: 0
Views: 713
Reputation: 694
You need only the first group of the match:
var subdomain = match.Success ? match.Groups[1].Value : null;
Upvotes: 7