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

Thanks,

I meant "(slash followed by anything except slash) to occur 0 or 1 time"

Basically 0 or 1 dir can appear inbetween /usr and bin/

  • Comment on Re^2: dir match, dir may or may not appear

Replies are listed 'Best First'.
Re^3: dir match, dir may or may not appear
by hippo (Archbishop) on Jan 12, 2016 at 10:34 UTC

    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.