代码如下:
string p = @"(http|https)://(?<domain>[^(:|/]*)"; Regex reg = new Regex(p, RegexOptions.IgnoreCase); Match m = reg.Match(HostUrl); Result=m.Groups["domain"].Value;
如http://localhost:8733/HVMsg/HVWcfService/获取的是:localhost
如http://guonei.news.baidu.com/n?cmd=1&class=shizheng获取的是:guonei.news.baidu.com