日期:2014-05-20 浏览次数:20886 次
public class test{
public static void main(String[] args){
Pattern p = Pattern.compile("\\d{3,5}");
String s = "123-34345-234-00";
Matcher m = p.matcher(s);
System.out.println(m.matches());
System.out.println(m.find());
System.out.println(m.find());
System.out.println(m.find());
System.out.println(m.find());
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class test2{
public static void main(String[] args){
Pattern p = Pattern.compile("\\d{3,5}");
String s = "123-34345-234-00";
Matcher m = p.matcher(s);
System.out.println(m.matches());
System.out.println(m.find()+"start at:"+m.start()+" end at:"+m.end());
System.out.println(m.find()+"start at:"+m.start()+" end at:"+m.end());
// System.out.println(m.find()+"start at:"+m.start()+" end at:"+m.end());
// System.out.println(m.find()+"start at:"+m.start()+" end at:"+m.end());
m.reset();
System.out.println(m.find()+"start at:"+m.start()+" end at:"+m.end());
System.out.println(m.find()+"start at:"+m.start()+" end at:"+m.end());
}
}