代码如下:

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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-12-22
  • 2021-10-20
  • 2021-07-12
相关资源
相似解决方案