|
In a message dated 2/16/2006 2:15:44 P.M. Eastern Standard Time,
[EMAIL PROTECTED] writes:
> How about a slight variation :
> > foreach ('123', '123.', '123.txt', '123.some.txt', '123.some.text.txt') { > /^(?:(.*)\.[^.]+|(.*)\.|([^.]+))$/; > print $1 || $2 || $3, "\n"; > } /^ (.+?) (?: \. [^.]*)? $/ seems simpler (?) to me, but both fail if
we try to include
the default directories dot and dotdot (even though this wasn't specified
originally):
printf qq(%15s --> %-15s \n), $_, /^ (.+?) (?: \. [^.]*)?
$/x
for qw(. .. 123 123. 123.txt 123.txt. 123.txt.txt 123.txt.txt. 123.txt.txt.txt);
. -->
.
.. --> . [FAILS] 123 --> 123 123. --> 123 123.txt --> 123 123.txt. --> 123.txt 123.txt.txt --> 123.txt 123.txt.txt. --> 123.txt.txt 123.txt.txt.txt --> 123.txt.txt however, the substitution approach you suggested can fairly painlessly
be
extended to include these cases:
for (qw(. .. 123 123. 123.txt 123.txt. 123.txt.txt 123.txt.txt.))
{
my $f; ($f = $_ ) =~ s/ (?<= [^.] ) \. [^.]* $ //x; printf qq(%15s --> %-15s \n), $_ , $f; } . --> . .. --> .. 123 --> 123 123. --> 123 123.txt --> 123 123.txt. --> 123.txt 123.txt.txt --> 123.txt 123.txt.txt. --> 123.txt.txt bill walters
|
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
