字符串是一个网址,比如:"http://msdn.microsoft.com/en-us/library/system.uri.host.aspx"求一正则表达式,能提取出网址中的基础地址,比如上面就是"http://msdn.microsoft.com" (尾部不带'/')

解决方案 »

  1.   

    string str="";
    Path.GetFileName(str)
    str.SubString(str.Indexof("/"));
      

  2.   

    regx ="http//:([^/]*)";
    每个匹配出来的字符串前都再加一个http://  
      

  3.   

            Match m = Regex.Match(uri, @"([^/]|//)+");
            Console.WriteLine(m.Value);
      

  4.   

            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);
            }
      

  5.   

    string url = Regex.Match(url,@"^(http://)?[^/]+").Value;
      

  6.   

    string url = "你的网址";
    string result = Regex.Match(url,@"^(http://)?[^/]+").Value;