String b = "<td>[a]</td><td>[b]</td><td>[c]</td>"得到所有[]里面的东东。
我写的是String regex="(?:<td.*?>\\p{Punct})(.*?)(?:\\p{Punct}</td>)";
希望有更好的方法,只要[]里面的。

解决方案 »

  1.   

    import java.util.regex.*; 
    public class Test1 

        public static void main(String[] args) 
        { 
            String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>";
            String regex="(?<=\\[)\\w*(?=\\])";
            Matcher m=Pattern.compile(regex).matcher(b); 
          while(m.find()){ 
                System.out.println(m.group()); 
                
            } 
        } 

    测试结果
    a
    b
    c
      

  2.   

    String regex = "(?:\\[(.*?)\\])";
      

  3.   

    package javaTest;import java.util.regex.*;
    public class Sample 
    {
    public static void main(String args[])
    {
    String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>";
            String regex="\\[(.*?)\\]";
            Matcher m=Pattern.compile(regex).matcher(b); 
            while(m.find()){ 
                System.out.println(m.group(1)); 
            } 
    }
    }
    测试结果:
    a
    b
    c
      

  4.   

    package javaTest;import java.util.regex.*;
    public class Sample 
    {
    public static void main(String args[])
    {
    String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>";
            String regex="\\[(.*?)\\]";
            Matcher m=Pattern.compile(regex).matcher(b); 
            while(m.find()){ 
                System.out.println(m.group(1)); 
            } 
    }
    }
    测试结果:
    a
    b
    c
      

  5.   


    public class Test {
    public static void main(String[] args) {
    String str = "<td>[a]</td><td>[b]</td><td>[c]</td>";
    String a=str.replaceAll("(<td>)|(</td>)|\\[|\\]","");
        System.out.println(a);
    }
    }result:abc