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;
子域的结果始终为:tenant1.example.be
而不仅仅是tenant1
。
任何?
答案 0 :(得分:7)
您只需要匹配的第一组:
var subdomain = match.Success ? match.Groups[1].Value : null;