加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则匹配连续三个数字

发布时间:2020-12-14 02:26:23 所属栏目:百科 来源:网络整理
导读:public class monkeycode {public static void main(String[] args) {String reg = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)|9(?=0))+d";String str = "123465478912312311112220";Matcher m = Pattern.compile(reg).matcher(
public class monkeycode {

	public static void main(String[] args) {

		String reg = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)|9(?=0))+d";
		String str = "123465478912312311112220";
		Matcher m = Pattern.compile(reg).matcher(str);
		while(m.find()){
			if(m.group().length()>=3){
				str = str.replace(m.group().substring(0,3),"");
			}
		}
		String r2 = "([1]{3}|[2]{3}|[3]{2}|[4]{3}|[5]{3}|[6]{3}|[7]{3}|[8]{3}|[9]{3}|[0]{3})";
		System.out.println(str.replaceAll(r2,""));
		
	}

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读