You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tom Schindl <to...@gmx.at> on 2006/01/31 18:10:34 UTC
[OT]Re: RegEx Hell
on the other hand:
-----------------8<-----------------
my $bla = "/dir/subdir/file.ext";
$bla =~ /(\w+\.\w+)$/;
print $1 . "\n"; # file.ext
-----------------8<-----------------
works perfectly
Mark Galbreath wrote:
> Close enough to perl, I hope...
>
> 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
Re: [OT]Re: RegEx Hell
Posted by John ORourke <jo...@o-rourke.org>.
or $bla=~/([^\/]+)$/; in case the filenames have non-alpha chars or more
dots...
Tom Schindl wrote:
>on the other hand:
>
>my $bla = "/dir/subdir/file.ext";
>
>$bla =~ /(\w+\.\w+)$/;
>print $1 . "\n"; # file.ext
>
>works perfectly
>
>