The "?" quantifier means to match 0 or 1 times as specified in the "Quantifiers" section of perlre. Therefore your pattern to match this could be simply (/[^/]+)? which is similar to QuillMeantTen's approach above.
In reply to Re^3: dir match, dir may or may not appear
by hippo
in thread dir match, dir may or may not appear
by hellosarathy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |