test = "hello [135]!!!!!![134]表情处理[134444444444444]";如这样的字符串 我需要得到 []号的值   
还需要得到 每一个[]的index值
谢谢各位

解决方案 »

  1.   


    import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test {
        public static void main(String[] args) {
            String str="hello [135]!!!!!![134]表情处理[134444444444444]";
            Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
            Matcher matcher = pattern.matcher(str);
            int i=0;
            while (matcher.find()) {
                System.out.println("index:"+(i++)+",Content:"+matcher.group());
            }
        }
    }
      

  2.   

    知道了    String str = "hello [135]!!!!!![134]表情处理[134444444444444]";
    Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
    Matcher matcher = pattern.matcher(str);
    int i = 0;
    while (matcher.find()) {

    System.out.println(matcher.start()+" :  "+matcher.end());

    System.out
    .println("index:" + (i++) + ",Content:" + matcher.group() );
    }
      

  3.   

      String str="hello [135]!!!!!![134]表情处理[134444444444444]";
      Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
      Matcher matcher = pattern.matcher(str);
      int i=0;
      while (matcher.find()) {
           System.out.println("StartIndex:"+ (matcher.start()-1));
           System.out.println( "EndIndex:"+(matcher.end()-1));
           System.out.println("index:"+(i++)+",Content:"+matcher.group());
    }
    这样就可以获取到了,每一个“[]”StartIndex 是开始的索引,EndIndex是结束的索引
      

  4.   

    String str="hello [135]!!!!!![134]表情处理[134444444444444]";
      Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
      Matcher matcher = pattern.matcher(str);
      int i=0;
      while (matcher.find()) {
    System.out.println("StartIndex:"+ (matcher.start()-1));
    System.out.println( "EndIndex:"+(matcher.end()-1));
    System.out.println("index:"+(i++)+",Content:"+matcher.group());
    }
    这个是好的
      

  5.   

    String str="hello [135]!!!!!![134]表情处理[134444444444444]";
      Pattern pattern = Pattern.compile("(?<=\\[).*?(?=\\])");
      Matcher matcher = pattern.matcher(str);
      int i=0;
      while (matcher.find()) {
    System.out.println("StartIndex:"+ (matcher.start()-1));
    System.out.println( "EndIndex:"+(matcher.end()-1));
    System.out.println("index:"+(i++)+",Content:"+matcher.group());
    }