I was needed to check if paths have correct names then I've created a regular expression as below:
^\/2\d{3}(\/2\d{3}-(0[1-9]|1[0-2])(\/[a-z ]+(\/(g|o)(\/[a-z ]+(\/s)?)?)?)?)?$
And it works for correct names but unfortunately, it also matches the wrong one like the next: /2020/2020-05/test/o/test. The last test is invalid I must decline this path.
Examples of correct paths:
/2020/2020-05/test/o/2020/2020-05/test/o/s(maximum, a nothing can be yet at the end)/2020/2020-05/test/2020/2020-05/2020
Examples of incorrect paths:
/2020/2020-05/test/o/2020/2020/2020-05/test/o/smth/2020/2020-05/test/test/o/2020/2020-05/test/o/o/smth- and so on
But as I know the question mark matches zero or one time so I cannot get what's wrong with my expression. Can anyone explain me, plz?
P.S. I use Python regular expressions if it's important.