我有这样一组xml里的标签 <value>http://www.aaa.com/bbb.htm    http://www.ccc.com.cn/ddd.htm?ee=ff   http://www.ggg.com/hh.asp   http://www.sss.com....</value>如果 我想把这样的一个字符串中的所有字段只保留主网址)(http://aaa.com),其他的部分全部都不要,用Regex的话应该怎么写?  循环后的东西可以放到数组里....求高人解答~~~~~~~

解决方案 »

  1.   

    http://[^/]+
    OR 
    http://.*?/
      

  2.   

    http://[^/]+
    OR 
    http://.*?/
      

  3.   

    MatchCollection mc=Regex.Matches(youstr,"http://(.*?)/");
    IList IL=null;
    foreach(string str in mc)
    {
    IL.Add(str);
    }
      

  4.   

    MatchCollection mc  MatchCollection = Regex.Matches(youstr, "http://\S+\.\S+", RegexOptions.IgnoreCase);//不要区分大小写
    foreach(string str in mc)
    {
     Console.WriteLine(str);
    }
      

  5.   

    MatchCollection mc=Regex.Matches(youstr,"http://(.*?)/");
    IList IL=null;
    foreach(string str in mc)
    {
    IL.Add(str);
    }