用正则匹配/和前面的内容,我这个是不严格匹配的,贪心匹配。
<script>
var url="http://community.csdn.net/Expert/test/PostNew.asp?room=304"
alert( url.match(/^.*\//) )
</script>

解决方案 »

  1.   

    <script language="javascript">
    <!--
    var str="http://community.csdn.net/Expert/test/PostNew.asp?room=304"
    var re=/.*(?=\/)/gi;
    alert(str.match(re));
    //-->
    </script>试试这个看看。
      

  2.   

    <script language="javascript">
    <!--
    var str="http://community.csdn.net/Expert/test/PostNew.asp?room=304"
    var re=/^.*(?=\/)/gi;
    alert(str.match(re));
    //-->
    </script>
    the top is wrong ,try this
      

  3.   

    <script   language=javascript>
    var   str="http://community.csdn.net/Expert/test/PostNew.asp?room=304"
    var   re=/^(.*?)\/[^\/]*?$/i;
    alert(str.replace(re,"$1"));
    </script>
      

  4.   

    var Browser = {};
    Browser.urlInfo = function(url)
    {
    if(/^(https?|ftp|file):\/\/([^:\/]+)(?::(\d*))?\/?(?:(.*)\/)?([^#?]*)\#?([^?]*)(?:\?(.*))?$/.test(url))
    {
    this.protocol = RegExp.$1;
    this.hostName = RegExp.$2;
    this.port = RegExp.$3;
    this.path = RegExp.$4;
    this.fileName = RegExp.$5;
    this.hash = RegExp.$6;
    this.param = RegExp.$7;
    this.rootUrl = [this.protocol,"://",this.hostName,(!/^\s*$/.test(this.port))?":"+this.port:""].join('');
    this.baseUrl = [this.rootUrl,this.path].join('/');
    this._data = null;
    }
    else
    return null;
    }var aa = new Browser.urlInfo("http://community.csdn.net/Expert/test/PostNew.asp?room=304");//这里是调用
    alert(aa.baseUrl + "/");
      

  5.   


    //还有个附带产品
    Browser.urlInfo.prototype = {
    getParam:function()
    {
    if(this._data!=null)return this._data;
    var data = {};
    while(/(?:\?|\&|^)([^=]*)=([^&]*)/g.exec(this.param))
    {
    var o = RegExp.$1;
    var v = unescape(RegExp.$2);
    if(data[o]==null)
    {data[o]=v;}
    else
    {
    if(data[o] instanceof Array)
    data[o][data[o].length] = v;
    else
    data[o]=[data[o],v];
    }
    o=v=null;
    }
    return this._data = data;
    }
    }
      

  6.   

    1楼的回答的确可以获得我想要的结果,不知道为什么mingxuan3000 给出的答案那么复杂呢?1楼的回答有什么问题吗?
      

  7.   

    ^(http://community.csdn.net/Expert/test/){1,1}.{1,}$呵呵