正则表达式 Matcher类find() reset()
本帖最后由 ljblxx 于 2013-09-22 22:24:59 编辑
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());
}
}