用正则式        :([^<]+)
去匹配字符串    <li>印  次:</l i>
会得到什么东西?
我以为是“”  或者是null,但都错了
这是匹配网页字符串的 一个东西       我匹配的网页如下,当当上的
http://product.dangdang.com/product.aspx?product_id=8965358

解决方案 »

  1.   

    我的本意是想取出 “印次:”和“<”之间的东西。
    如果存在就直接对它操作
    如果没有的话,就赋予它值“000”。
    比方说这个没有值,怎么把它赋为000.
    String s=null;
    if(result.group(1).trim()==""||result.group(1)==null){
     s="000";
    }
    else  s=result.group(1);
    但这个句子做不到     哪里错了?
      

  2.   

    上边if 条件写错了
    if(result.group(1).trim()==""  ||  result.group(1)==null) 
      

  3.   

    不能用==,用equals比较字符串
      

  4.   

    应该这样
    if(result.group(1)==null||result.group(1).trim().equals("")) 
      

  5.   

    都把我改糊涂了 , 我一开始用过这个*,也不行。
    equals方法对头!!
    郁闷了     我怎么把这给忘记了  
      

  6.   

      public static void main(String[] args) throws IOException {
        Pattern p = Pattern.compile(":([^<]+)");
        Matcher m = p.matcher("<li> 印  次: </l   i><");
        String msg = m.find() ? m.group(1).trim() : "000";
        if (msg.length() == 0) {
          msg = "000";
        }
        System.out.println(msg);
      }