sfantar schreef:
> As the path to a directory under Linux is like /file/file/file where
> file can be a word containing either - or _ .
> Which regexp can match this in the best way?
> I tried (/\w[-]?\w/)+ but it doesn't work well.
You have two slashes in there, as if you want to match
/file//file//file
Further, almost any character can be part of a filename.
m{ \A # From start-of-buffer,
(?: # start a non-capturing group
/ # that begins with a slash
[^/]+ # which is followed by 1 or more
# non-slash characters.
)+ # Match 1 or more groups
\z # until end-of-buffer.
}x
To capture the matched string in $1:
m{ \A # From start-of-buffer,
( # <start-of-capturing>
(?: # start a non-capturing group
/ # that begins with a slash
[^/]+ # which is followed by 1 or more
# non-slash characters.
)+ # Match 1 or more groups
) # <end-of-capturing>
\z # until end-of-buffer.
}x
See also Regexp::Common.
http://search.cpan.org/search?module=Regexp::Common
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>