前端之家收集整理的这篇文章主要介绍了
正则表达式--find lookingAt,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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
原文链接:https://www.f2er.com/regex/359198.html