靓号,java正则表达式的实现

移动号码规则配置文件patten.txt

## 移动号码规则
ABCD E (?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3}\d 1
AAAA E (\d)\1{3} 2
ABBB E (\d)((?!\1)\d)\2{2} 3
AAAB E (\d)\1{2}((?!\1)\d) 4
AABB E (\d)\1{1}((?!\1)\d)\2{1} 5
ABAB E (\d)((?!\1)\d)(\1\2){1} 6
AAAAA E (\d)\1{4} 7

测试代码

public static void main(String[] args) {
		Set<ModeDef> modeDefs = FileRead.getBaseData("C:\\TempData\\gz-workspace\\crmweb\\src\\patten.txt");
		
		// 测试号码
		List<String> chinaNums = Arrays.asList("1343433333", "1343423333", "1343443456"
				, "1343422333", "1343422223", "1343422233", "1343422323");
		
		for (String num : chinaNums) {
			for (ModeDef modeDef : modeDefs) {
				
				String pattern = null;
				if ("E".equals(modeDef.getModeTyte())) {
					pattern = ".*" + modeDef.getRegex() + "$";
				} else if ("A".equals(modeDef.getModeTyte())) {
					pattern = ".*" + modeDef.getRegex() + ".*";
				}
				
				boolean isMatch = Pattern.matches(pattern, num);
				if (isMatch) {
					System.out.println(num + " : " + modeDef.getModeDef());
					break;
				}
			}
		}
	}

测试结果

1343433333 : AAAAA
1343423333 : AAAA
1343443456 : ABCD
1343422333 : ABBB
1343422223 : AAAB
1343422233 : AABB
1343422323 : ABAB

QQ号码规则配置文件patten_qq.txt

## 移动号码规则
## QQ靓号规则
AAAAAAA A (\d)\1{6} 1
AAAAAA A (\d)\1{5} 2
AABBCC A (\d)\1((?!\1)\d)\2((?!\2)(?!\1)\d)\3 3
AAABBB A (\d)\1{2}((?!\1)\d)\2{2} 4
ABABAB A (\d)((?!\1)\d)(\1\2){2} 5
ABCABC A ((\d)((?!\2)\d)((?!\2)(?!\3)\d))\1 6
ABCDEF A (?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\d 7
FEDCBA A (?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5}\d 8
ABCCBA A (\d)((?!\2)\d)((?!\2)(?!\3)\d)\3\2\1 9
ABCFABC A ((\d)((?!\2)\d)((?!\2)(?!\3)\d))(\d+)\1 10
ABCFCBA A (\d)((?!\2)\d)((?!\2)(?!\3)\d)(\d+)\3\2\1 11
AAAAA A (\d)\1{4} 12
ABCDE A (?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){4}\d 13
EDCBA A (?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){4}\d 14
ABCD E (?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3}\d 15
AAAA E (\d)\1{3} 16
ABBB E (\d)((?!\1)\d)\2{2} 17
AAAB E (\d)\1{2}((?!\1)\d) 18
AABB E (\d)\1{1}((?!\1)\d)\2{1} 19
ABAB E (\d)((?!\1)\d)(\1\2){1} 20

测试代码

20
1233333331 : AAAAAAA
1233333311 : AAAAAA
1233445511 : AABBCC
1233355511 : AAABBB
1235353511 : ABABAB
1234534511 : ABCABC
1212345611 : ABCDEF
1287654311 : FEDCBA
1287667811 : ABCCBA
1876336781 : ABCCBA
1876338761 : ABCFABC

参考链接:https://blog.csdn.net/xhanguomzhu/article/details/79993782

你可能感兴趣的:(编程)