方法如下:Pattern p = Pattern.compile("a"); Matcher m = p.matcher("aaaaab"); while(m.find()){ System.out.println(m.start()); }