地址如下:
http://rs320tl.rapidshare.com/files/119371167/sth.rar
我要用Regex选择
rs320tl.rapidshare.com
,但是我对正则表达式不熟悉。你能指导我吗?
谢谢。
PS。
地址中的
rs320tl
是可变的。
最佳答案
如果您真的想沿着Regex / C#路线走,我想您正在寻找的是这样的东西:
string sOriginalUrl = "http://rs320tl.rapidshare.com/files/119371167/sth.rar";
string sPattern = "http://(?'host'[0-9a-zA-Z-.]*)/.*";
Regex re = new Regex(sPattern, RegexOptions.ExplicitCapture);
string sHost = re.Match(sOriginalUrl).Groups["host"].Value;
关于c# - 在C#中选择带有正则表达式的主机名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2294028/