import java.io.*;
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
String str = "12345";
String regex="\\d\\d\\d";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
count++;
System.out.println(m.group());
System.out.println(count);
}
System.out.println(count);
}
private static int count;
}
为何打印出来是
123
1
1
而不是
123
1
234
2
345
3
3
???求教
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
String str = "12345";
String regex="\\d\\d\\d";
Matcher m=Pattern.compile(regex).matcher(str);
while(m.find()){
count++;
System.out.println(m.group());
System.out.println(count);
}
System.out.println(count);
}
private static int count;
}
为何打印出来是
123
1
1
而不是
123
1
234
2
345
3
3
???求教
[align=left] String str = "123456";
int start=0;
while (start+2<str.length()) {
System.out.println(str.substring(start,start+3));
start++;
} [/align]