前端之家收集整理的这篇文章主要介绍了
正则表达式匹配不确定重复,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
404_0@从一堆手机号码中,找出xyz可不连续且重复3次的手机号码
package test
import java.util.regex.Matcher
import java.util.regex.Pattern
public class Main {
public static Pattern pattern=Pattern.compile("(\\d{3})(.*\\1){2}")
public static void main(String[] args) {
String s1="13620446688"
Matcher m1=pattern.matcher(s1)
System.out.println(m1.find())
String s2="13613613600"
Matcher m2=pattern.matcher(s2)
System.out.println(m2.find())
String s3="13601360136"
Matcher m3=pattern.matcher(s3)
System.out.println(m3.find())
}
}
@H_
404_0@\1表示重复第一个括号里的
内容