我想重写url
例如:
http://localhost:8080/j2eeweb/pour/driverCase.action?cdid=40D748E8CCF410C4将它改写成
http://localhost:8080/j2eeweb/pour/40D748E8CCF410C4.html
不知道这个正则怎么写

解决方案 »

  1.   

    LZ,可自己看看正则教程,然后自己解决吧。http://deerchao.net/tutorials/regex/regex.htm
      

  2.   

    String url = "http://localhost:8080/j2eeweb/pour/driverCase.action?cdid=40D748E8CCF410C4";
    String prefix = url.subString(0,url.lastIndexOf("/") + 1);
    String res = prefix + url.replace("\\.+","40D748E8CCF410C4.html
    ");
    考虑到你只替换部分内容, 就这样整下得了,, 当然要写一个完整的正则也行吧.!  这个我也得看文档去.! 呵呵 ,每次遇到复杂的正则都是现去看文档说明滴
      

  3.   


    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class PatternTest { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub String str="http://localhost:8080/j2eeweb/pour/driverCase.action?cdid=40D748E8CCF410C4";
    parse(str);
    }
    private static void parse(String str)
    {
    String pa="\\/[^\\/]*?(\\?cdid=)(.*?)";
    Pattern p=Pattern.compile(pa);
    Matcher m=p.matcher(str);
    String target="";
    if(m.matches())
     target=m.group(2);
    String result=str.replaceAll(pa,"/"+target);
     result+=".html";
    System.out.println(result);
    }}输出http://localhost:8080/j2eeweb/pour/40D748E8CCF410C4.html