Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: dir match, dir may or may not appear

by QuillMeantTen (Friar)
on Jan 12, 2016 at 09:17 UTC ( [id://1152540]=note: print w/replies, xml ) Need Help??


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

In your regex [^/]+{0,1} does not make sense if I understand it correctly, basically you say
anything but a slash, at least one time, then you say at least 0 time at most 1... you gotta choose which you want, either it is

[^/]+ or [^/]? (equivalent to {0,1}) For what you want to do I'd say: m#\A/usr/([^/]+/)?bin#

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

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found