public static void main(String[] args) {
String str = "ewscdsmvvdkld4375347584zzzzzzfff7843957";
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(str);
//是否存在匹配的字符串
while(matcher.find()){
//4375347584,13,23
//7843957,32,39
//获取匹配到的字符串
System.out.println(matcher.group());
//获取的子字符串第一个字符在原字符串的下标
System.out.println(matcher.start());
//获取的子字符串最后一个字符在原字符串的下标
System.out.println(matcher.end());
}
}
字符串匹配:Pattern和Matcher
最新推荐文章于 2023-11-22 23:27:54 发布