URL:http://localhost/post.do?paramId=1&paramName=name#top
在JAVA中用正则表达式获取到 post.do

解决方案 »

  1.   

    public static String getHref(String href){
    Pattern s=Pattern.compile("http://localhost/(.*)\\?");
    Matcher m=s.matcher(href);
    if(m.find())
    return m.group(1);
    else
    return null;
    }
      

  2.   

    public static String getHref(String href){
    Pattern s=Pattern.compile("http://.*/(.*)\\?");
    Matcher m=s.matcher(href);
    if(m.find())
    return m.group(1);
    else
    return null;
    }
      

  3.   

    这样不对哦,要是我的页面再加个文件夹的名称就出错了
    比如说 
    URL:http://localhost/user/post.do?paramId=1&paramName=name#top
      

  4.   

    而且要是URL是这样的怎么办呢
    URL:http://localhost/user/post.do我这里倒是有一个JS的正则表达式,就是不知道怎么转换成JAVA的,高人啊,帮帮忙return location.href.replace(/^.*\/([^\/\?^\/\#]*).*$/,"$1");
      

  5.   

    http\:\/\/localhost\/\w+\.\w+|http\:\/\/((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?\/\w+\.\w+
    这个正则表达式适用于http://localhost的和http://192.168.8.8这种的。希望对你有帮助
      

  6.   

    http\:\/\/localhost\/(w+\/)*\w+\.\w+
    这个应该匹配URL:http://localhost/   后加入多个文件夹的
      

  7.   

    http\:\/\/localhost\/(\w+\/)*\w+\.\w+
    楼主,我刚才试了下,这个可以符合你的要求。域名变化也可以,路径多几个文件夹也可以。
      

  8.   

    我的这个是正确的
    Pattern s=Pattern.compile("http://.*/(.*)\\?");
    我测试了 及时多个文件夹名也没问题
    public static String getHref(String href){
    Pattern s=Pattern.compile("http://.*/(.*)\\?");
    Matcher m=s.matcher(href);
    if(m.find())
    return m.group(1);
    else
    return null;
    }
    你试试?肯定对的取组~以这个开使 以?结束