您的位置:首页 > 其它

正则表达式--find lookingAt

2016-06-03 10:47 375 查看
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainClass {

public static void main(String arg[]) {

String string="123-34345-234-00";

Pattern pattern = Pattern.compile("\\d{3,5}");
Matcher matcher = pattern.matcher(string);

boolean result1= matcher.matches();
System.out.println("result1="+result1);

//重置匹配器。
matcher.reset();

//尝试查找与该模式匹配的输入序列的下一个子序列。
boolean result2 = matcher.find();
System.out.println("result2="+result2);
boolean result3 = matcher.find();
System.out.println("result3="+result3);
boolean result4 = matcher.find();
System.out.println("result4="+result4);
boolean result5 = matcher.find();
System.out.println("result5="+result5);

//尝试将从区域开头开始的输入序列与该模式匹配。
boolean result6 = matcher.lookingAt();
System.out.println("result6="+result6);
boolean result7 = matcher.lookingAt();
System.out.println("result7="+result7);
boolean result8 = matcher.lookingAt();
System.out.println("result8="+result8);
}
}


result1=false
result2=true
result3=true
result4=true
result5=false
result6=true
result7=true
result8=true
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: