A friend of mine had this as a task for university.
He needed a Regex to check if a 9 digit long number with leading 0+
has no more 0
s after another digit.
Examples:
000001111 - good
000000010 - bad
000000000 - good
001215341 - good
165160000 - bad
0165168546 - bad
After some time we both came up with ^\b([0]+[1-9]*)\b$
.
However this also allows the latest example/ does not check for the correct length. He ended up checking the length with an if-statement beforehand, but I just can't find my peace because of it.
Is there an more elegant way? One Regex to do the above, but also check the length?