String str="<td align='center'>aaaaa</td>";
String  r="(<td align='center'>)(.*)(</td>)";
Pattern s=Pattern.compile(r);
Matcher m = s.matcher(str);如上,在java里面我想用变量获取其中aaaaa的值,请问我应该怎么做呢?

解决方案 »

  1.   

    String r = "<[^<|>]*>";
      

  2.   

    String r = "<[^<|>]*>";
    这个我没有看懂,但是我还是用了
    String  r="(<td align='center'>)(.*)(</td>)";
    Pattern s=Pattern.compile(r);
    Matcher m = s.matcher(str);

    boolean T=m.matches();
    if(T)
    {
    //String a=".*";
    String q = "<[^<|>]*>";
    Pattern d=Pattern.compile(q);
    Matcher n=d.matcher(str);
    boolean t=n.matches();
    if(t){
    System.out.print(q.toString());
    }else 
    System.out.print("false!");

    }大写的T返回的是true,小写的t返回的是false
    是不是上面那句有问题呀??
      

  3.   

    public static String test(String str){
              Pattern pattern = Pattern.compile("<[^<|>]*>");
              //Pattern pattern1 = Pattern.compile("&nbsp;");
              Matcher matcher = pattern.matcher(str);
              String returnStr = matcher.replaceAll("");
              //Matcher matcher1 = pattern.matcher(returnStr);
              return returnStr;      }
      

  4.   

    String str="<td align='center'>aaaaa</td>";
    String r ="(<td align='center'>)(.*)(</td>)";
    System.out.println(str.replaceAll(r, "$2"));
      

  5.   

    String str="<td align='center'>aaaaa</td>";
    String  r="(<td align='center'>)(.*)(</td>)";
    Pattern s=Pattern.compile(r);
    Matcher m = s.matcher(str);
    String s1=m.group(1);
    就可以了
      

  6.   

    String  r="^<.*>(.*)<\\/>";
    r换成这个
      

  7.   

    谢谢malligator,zhaochunhui两位大哥,你们两人的方法都可行.再次感谢