in reply to Regex To Remove File Extension
There are a lot of ways to skin this cat:
s/\..*+$//; s/\-[^\.]*$//;
Both of these use $ at the end to anchor the regex to the end of the string. The first uses .*+, the non-greedy version of .*, the second uses the character class of all chars except '.' to only get the last suffix
Another possibility is to use the perl module File::Basename and this is probably the best way, because you don't need to worry about getting it right, someone else did that already
UPDATE: kennethk is right, the first version doesn't work. Obviously the regex engine never matches from right to left even when anchored to the right
UPDATE2: Seems to be not my day. 3 errors in two lines is quite depressing
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regex To Remove File Extension
by kennethk (Abbot) on Dec 10, 2008 at 19:17 UTC | |
Re^2: Regex To Remove File Extension
by Narveson (Chaplain) on Dec 10, 2008 at 20:14 UTC | |
by Nkuvu (Priest) on Dec 15, 2008 at 16:23 UTC |
In Section
Seekers of Perl Wisdom