I have a string of numbers and each number can appear either zero or one time in the string. Can I validate this via RegEx? I could do something like check the character array for duplicates, but would prefer to stick to my normal validation routine.
The following should return “Match”
String thisItemText = "12679";
if(!thisItemText.matches("[1245679]*")) {
System.out.println("No Match");
} else {
System.out.println("Match");
}
The following should return “No Match” (note the double “2”)
String thisItemText = "122679";
if(!thisItemText.matches("[1245679]*")) {
System.out.println("No Match");
} else {
System.out.println("Match");
}
The regex
(\d).*\1will match if there’s a repeated digit.