in reply to duration regex
But how do you verify the order of appearance of Y followed by M followed by D followed by H followed by M followed by S (YMDHMS) with [Y|M|D|H|S]?
It sounds like you need a little more than a regular expression to parse the duration string.
How about a function, say, is_duration that checks the duration string passed in by first tokenize the string, and then validate the tokens by iterating through them. Return error when a bad token is encountered.
You can have a look at parsers like the Parse::RecDescent for doing this sort of things, and it is not too hard to write such a validator either.