<html><head>       <title> </title>       <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="description" content="497"></head><body><script language="JavaScript"> location.href="https://172.16.250.11/mw0202/my/default.do?siteurl=callbacktest";</script>
</body></html>以上是一段html,现在我想分离出来location.href的内容( 一个url地址:https://172.16.250.11/mw0202/my/default.do?siteurl=callbacktest)
各位有什么好的,比较通用的办法,当然这个url是可以有很多种情况的,比如包含一些特殊字符什么的.

解决方案 »

  1.   

    int i = s.indexOf("https://");
    int j = s.indexOf("</script>");String result = s.substring(i,j-2);
      

  2.   

    public class Test
    {
        private String pattern;
        private String match;
        
        public Test()
        {   
        }
        public Test(String pattern,String match)
        {
            this.pattern=pattern;
            this.match=match;
        }
        
        
    /**
     * @return 返回 match。
     */
    public String getMatch()
    {
    return match;
    }
    /**
     * @param match 要设置的 match。
     */
    public void setMatch(String match)
    {
    this.match=match;
    }
    /**
     * @return 返回 pattern。
     */
    public String getPattern()
    {
    return pattern;
    }
    /**
     * @param pattern 要设置的 pattern。
     */
    public void setPattern(String pattern)
    {
    this.pattern=pattern;
    }
        public void print()
        {
            Pattern p=Pattern.compile(pattern);
            Matcher result=p.matcher(match);
            
            while(result.find())
                System.out.println(result.group());
        }
        public static void main(String[] args) throws Exception 
        {
            Test t=new Test();
            String pattern="location.href=https://([A-z/.=?]*\\d*)*";        String match="location.href=https://172.16.250.11/mw0202/my/default.do?siteurl=callbacktest";
            t.setMatch(match);
            t.setPattern(pattern);
            t.print();
        }
    }
      

  3.   

    Pattern p = Pattern.compile("location.href=\"(.+)\"");
            Matcher m = p.matcher("location.href=\"as.awe.rw\"");
            while(m.find()){
                System.out.println(m.group(1));
            }