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


in reply to dir match, dir may or may not appear

What syntax error and where? Perl is usually quite informative with its error messages.

Most likely, it's a syntax error in your regular expression. See perlre, especially about quantifiers.

Personally, I would reformulate the problem as "any directory that starts with /usr/ and ends with /bin, and do the checking in two regular expressions instead.

Replies are listed 'Best First'.
Re^2: dir match, dir may or may not appear
by hellosarathy (Novice) on Jan 12, 2016 at 09:13 UTC
    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...?

      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!;

      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