Correct input format: xxxx/yyyy/zzzz i.e. 4 chars for each part. Total length of the string (not counting "/") should always be 12.
Input can be: xxx/yyy/zzz then it should be padded to come out as 0xxx/0yyy/0zzz
At this stage at least one "/" will be there. If there are 2 parts then we need 6 chars for both.
Looking for a regex with padding logic in Scala.
// line to tune:
val matchThis = raw"(\d{4})/(\d{4})/(\d{4})".r
val valids = List ("1/6", "123456/1", "1/123456", "123456/123456", "1/2/3", "1234/1234/1234", "012/12/3", "1/01/012")
val invalids = List ("/6", "1234567/1", "1/1234567", "1234567/1234567", "/2/3", "1/2/", "12345/1234/1234", "012/12345/3", "1/01/012345")
def tester (input: String) = {
input match {
case matchThis(_*) => "It's valid!"
case _ => "Need some work" /*???*/
}
}
valids.map (s => tester(s))
invalids.map (s => tester(s))