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


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

the regexp has errors:
Nested quantifiers in regex marked by <-- HERE in m/^/usr/(/[^/]+{ <- +- HERE 0,1})/bin//
Two expressions is fine,is there a one liner, as this could increase in future...?

Replies are listed 'Best First'.
Re^3: dir match, dir may or may not appear
by Corion (Patriarch) on Jan 12, 2016 at 09:18 UTC

    Yes, see perlre. If one expression is too difficult, why not use two?

    If you really need to write it in one expression, use a group and quantify that:

    m!^/usr(?:/[^/]+)?/bin!;
Re^3: dir match, dir may or may not appear
by Anonymous Monk on Jan 12, 2016 at 09:20 UTC

    a quantifier is +

    a quantifier is {0,1}

    You can't have {0,1}{0,1}{0,1}{0,1}

    You can't have +{0,1}+{0,1}

    If you want a pattern ([^/]+) to repeat, you have to group it

    perlre, perlretut, perlrequick describe these words I've used, go fish