我有一串数字,每个数字在字符串中可以显示为零或一次.我可以通过RegEx验证吗?我可以做一些像检查字符数组的重复项,但更喜欢坚持我的正常验证例程.
以下应返回"匹配"
String thisItemText = "12679";
if(!thisItemText.matches("[1245679]*")) {
System.out.println("No Match");
} else {
System.out.println("Match");
}
Run Code Online (Sandbox Code Playgroud)
以下应返回"No Match"(注意双"2")
String thisItemText = "122679";
if(!thisItemText.matches("[1245679]*")) {
System.out.println("No Match");
} else {
System.out.println("Match");
}
Run Code Online (Sandbox Code Playgroud)