in reply to filtering folder path using regex.
Now onto the regex. Pay special attention to the ".+" explanation, and then#!/usr/bin/perl -l my $yo = 'C:/as/d/f/e/r/g/a/d/f/g/'; use File::Spec; print for File::Spec->splitpath($yo); warn $yo; print for File::Spec->splitdir($yo); die $yo; __END__ C: /as/d/f/e/r/g/a/d/f/g/ C:/as/d/f/e/r/g/a/d/f/g/ at - line 5. C: as d f e r g a d f g C:/as/d/f/e/r/g/a/d/f/g/ at - line 7.
update: yuckyish (File::Spec rocks)use YAPE::Regex::Explain; die YAPE::Regex::Explain->new(qr/^(\w):\\(.+)\\?/)->explain; __END__ The regular expression: (?-imsx:^(\w):\\(.+)\\?) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- \w word characters (a-z, A-Z, 0-9, _) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- : ':' ---------------------------------------------------------------------- \\ '\' ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- .+ any character except \n (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- \\? '\' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
perl -le"print for split m{[:\\/]+}, shift, 3" C:\y\o\d\a C y o\d\a
| MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!" | |
| I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README). | |
| ** The third rule of perl club is a statement of fact: pod is sexy. |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: filtering folder path using regex.
by blackadder (Hermit) on Jul 13, 2003 at 14:33 UTC | |
by blackadder (Hermit) on Jul 15, 2003 at 13:09 UTC | |
|
Re: Re: filtering folder path using regex.
by barbie (Deacon) on Jul 14, 2003 at 09:14 UTC | |
by PodMaster (Abbot) on Jul 14, 2003 at 09:59 UTC | |
by barbie (Deacon) on Jul 14, 2003 at 17:23 UTC |