http://qs321.pair.com?node_id=1152547


in reply to Re^2: dir match, dir may or may not appear
in thread dir match, dir may or may not appear

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.