Match m = Regex.Match(uri, @"([^/]|//)+"); Console.WriteLine(m.Value);
string[] uris = new string[] {"http://www.google.com/asfasldfj","https://www.baidu.com/sdfasdf","ftp://www.alibaba.cm/s/dfasdf","www.google.com.cn/asfdsdf","cn.yahoo.com/asdfl","http://cn.yahoo.com/sdf" }; Regex reg = new Regex(@"([^/]|//)+"); foreach (string uri in uris) { Console.WriteLine(reg.Match(uri).Value); }
Path.GetFileName(str)
str.SubString(str.Indexof("/"));
每个匹配出来的字符串前都再加一个http://
Console.WriteLine(m.Value);
Regex reg = new Regex(@"([^/]|//)+");
foreach (string uri in uris)
{
Console.WriteLine(reg.Match(uri).Value);
}
string result = Regex.Match(url,@"^(http://)?[^/]+").Value;