On 1/31/06, Mark Galbreath <[EMAIL PROTECTED]> wrote: > > Close enough to perl, I hope...
this kind of question would best go to your local perl mongers chapter but anyway, I'll break the rules for someone from the General Accounting Office on the occasion of the retirement of Mr. Greenspan... > I'm trying to string the filename from the path: > > /dir/subdir/file.ext => file.ext > > with > > /\w+\.\w+$/ > > and am getting the entire path returned. I am falling asleep reading the > perldoc regex "intro," "tutorial," full doc, and even Jeffrey Friedl's > "Mastering Regular Expressions." This can't be this difficult nor unusual! > Why can't I find an example somewhere or get this to work? Better yet, > somebody please profer a solution? :-) > > mark Where are your capturing parentheses? my ($path,$filename) = $path_and_filename =~ m#^(.*?)/([^\]+)$#; # using # instead of / for clarity # ^ anchor at beginning of string # ? non-greedy match modifier, which, on reflection, # might actually make this less efficient # / literal slash # [^/] character class matching anything but slash # $ end-of-string anchor there's a module that deals with paths and file names in a non-os-specific way Those documents may be dull, but they made PERFECT SENSE TO WHOEVER WROTE THEM and if you can figure out a better way to say something that is in one of them you can get your name in the authors file. I reccommend mark jason dominus's regular expression discussions which are somewhere on plover.com for a good discussion of how regexen work. Have a nice day! -- David L Nicol "To get the present numbers and diversity of snails on the Hawaiian Islands, for instance, Cowie and his colleagues figure that they'd only need one snail-carrying, hurricane-driven leaf to reach the islands every 10,000 years."