Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: dir match, dir may or may not appear

by Corion (Patriarch)
on Jan 12, 2016 at 08:58 UTC ( #1152538=note: print w/replies, xml ) Need Help??

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:


      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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1152538]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-08-15 13:02 GMT
Find Nodes?
    Voting Booth?

    No recent polls found