The general format is:
YYYY/MM/DD/INFO
- Only the separators
/
are mandatory. - Each part is optional.
YYYY
- exactly 4 numbers.MM
- exactly 2 numbers.DD
- exactly 2 numbers.INFO
- any sequence of letters, spaces or hyphens.
So these are valid strings:
2020/06/25/XYZConf
2020///XYZConf
2020//25/XYZConf
2020/06//XYZConf
//25/XYZConf
///
I'm really struggling to come up with a regex that validates optional parts while maintaining the integrity of the string as a whole.
How would you write this regular expression?
PS: This needs to be a regular expression as it will be part of a third-party lexer that doesn't accept anything else.
Relevant posts: