in reply to Re^2: My regex works, but I want to make sure it's not blind luck
in thread My regex works, but I want to make sure it's not blind luck
There are many modules like: File::Basename.use strict; use warnings; foreach my $test ('..', 'file.txt', 'blah.abc.txt') { my ($suffix) = $test =~ /(\.[^.]+)$/; $suffix //= ''; #suffix is null string if no match print "test=$test suffix=$suffix\n"; } __END__ test=.. suffix= test=file.txt suffix=.txt test=blah.abc.txt suffix=.txt
Update: I guess probably: my ($suffix) = $test =~ /(\.\w+)$/;
Word characters are A-Za-z0-9_. Space and control chars are not allowed.
|
|---|