I'm trying to match a String input with the criteria below:
- The first characters are unique lowercase English letters
- The next characters are the represent the current year from 1500 to 2020
- The next characters can only be 10, or 100, or 1000
- The last character will be a digit 0 through 9
The regex string that I have created that I believe is mostly correct is with explanation is:
String validRegex =
"^"+ # start of string
(?=.*[a-z].*[a-z].*[a-z])"+ # Ensure string has only 3 consecutive lowercase English letters
"(?=.*[0-9].*[0-9].*[0-9].*[0-9])"+ # Ensure string has only 4 digits representing year i.e. 2020
"(?=.*([0-9].*[0-9]) | ([0-9].*[0-9].*[0-9]) | ([0-9].*[0-9].*[0-9].*[0-9]))"+ # Ensure 10, 100, or 100 digits
"(?=.*[0-9])"+ # Ensure last character is a digit 0-9
"(?=\\S+$)"+ # Ensure string has no whitespace
".{10,12}"+ # Entire string length must be from 10 through 12 characters
"$"; # end of string
Is there a simple way to update my regex expression such that I can detect for only unique consecutive characters?