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
。
有没有人?
发布于 2017-06-28 15:20:52
您只需要匹配的第一组:
var subdomain = match.Success ? match.Groups[1].Value : null;
https://stackoverflow.com/questions/44806576
复制