实现以下效果:
*若是[虚拟目录]-http://localhost/Store.WebSite/default.aspx  则返回 http://localhost/Store.WebSite/
(注:Store.WebSite为虚拟目录名 localhost代表本机,也有可能是机器名,也有可能是ip)*若是[站点]-www.Store.com/default.aspx  则返回 www.Store.com要求:
用正则实现,以下思路提供者勿扰:substring+indexOf 

解决方案 »

  1.   

    Regex r1 = new Regex("localhost/Store.WebSite/default.aspx"); 
    Regex r2 = new Regex("www.Store.com/default.aspx"); 
    Match m1 = r1.Match(url1);
    Match m2 = r2.Match(url2);
    if (m1.Success) 
    {
    ...
    }
    if (m2.Success) 
    {
    ...
    }
      

  2.   

    /*
    * 若是[虚拟目录]-http://localhost/Store.WebSite/default.aspx  则返回 http://localhost/Store.WebSite/ 
    (注:Store.WebSite为虚拟目录名 localhost代表本机,也有可能是机器名,也有可能是ip) 
    *若是[站点]-www.Store.com/default.aspx  则返回 www.Store.com

    */string[] str = new string[] { "http://localhost/Store.WebSite/default.aspx", "www.Store.com/default.aspx", "http://127.0.0.1/Store.WebSite/t.jsp" };         
    foreach (string s in str)
    {
        Console.WriteLine(Regex.Match(s, @"(http://)?.+/(?=.+\.[a-z]+)", RegexOptions.IgnoreCase).Value);
    }/*
    http://localhost/Store.WebSite/
    www.Store.com/
    http://127.0.0.1/Store.WebSite/
    请按任意键继续. . .
    */
      

  3.   

     我帮你做了个看看。    var str = "www.Store.com/default.aspx"  //or http://localhost/Store.WebSite/default.aspx;
        var reg = /(.*\/)[^\/]*/g;
        if(reg.test(str))
        document.write(RegExp.$1);