问题
Im looking to create a RegEx for java to validate a Pin Number that needs to be at least exactly 6 character long and not all numbers can be equal.
I got /\d{6}/ but I I'm having a little trouble finding out how to make sure all 6 numbers should be different, so 000000 is invalid, while 000001 should be fine.
回答1:
You can use this regex with a negative lookahead assertion:
^(\d)(?!\1+$)\d{5}$
RegEx Demo
RegEx Details:
^: Start(\d): Match and capture first digit in group #1(?!\1+$): Negative lookahead to assert we don't have repetitions of same digit till end\d{5}: Match remaining 5 digits$: End
来源:https://stackoverflow.com/questions/46435883/regex-for-pin-number