public class P296Pattern {
   public static void main(String[] args) {
      Pattern x = Pattern.compile("\\w");
      Matcher m = x.matcher("aasdfasdf adsfasdf23");
      while(m.find()){
         System.out.println(m.start()+ " ");
      }
   }
}

解决方案 »

  1.   

    what's the matter???
    是想找出字母??[a-zA-Z]
      

  2.   

    嗯,你想把那些字符输出?把m.start()换成m.group()
      

  3.   


    import java.util.regex.*;public class P296Pattern {
       public static void main(String[] args) {
          String str = "aasdfasdf adsfasdf23";
          Pattern x = Pattern.compile("\\w");
          Matcher m = x.matcher(str);
          while(m.find()){
             System.out.println(str.charAt(m.start())+ " ");//这样就好了,m.start返回的就是匹配
                                                             // 成功的索引
          }
       }
    }建议多看API文档!
      

  4.   

    import java.util.regex.*;public class P296Pattern {
       public static void main(String[] args) {
             String str = "aasdfasdf adsfasdf23";
          Pattern x = Pattern.compile("\\w");
          Matcher m = x.matcher(str);
          while(m.find()){
             System.out.println(m.group());
          }
       }
    }ls的结果应该和这个是一样的,每行输出每个英文/数字字符
      

  5.   

    lz是不是,不想要那些数字。你用“\\w”匹配时“数字”也当做一个字符来处理的
    你试试这个是不是你要的
    public static void main(String[] args) {
            String str = "aasdfasdf adsfasdf23";
            Pattern x = Pattern.compile("[a-z|A-Z]");
            Matcher m = x.matcher(str);
            while(m.find()){
               System.out.print(m.group());   //the result :aasdfasdfadsfasdf
          
            }
    }
      

  6.   

    <input value='大家好!'/>
      

  7.   

    首先\w就相当于字母和数字的组合。
    其次m.group()才是得到匹配的结果。而m.start得到的当次匹配成功的开始位置。你也可以通过m.end得到匹配成功的结束位置。
      

  8.   


     LZ 应该说清楚点,我想 m.group() 和 m.start()的区别应该知道吧
      

  9.   


     这个单个字符的分组 m.group() 就行了吧,不用那么麻烦吧