Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Pattern Matching 2

Status
Not open for further replies.

kennygadams

Programmer
Joined
Jan 2, 2005
Messages
94
Location
US
I'm trying to get file extensions by pattern matching but I run into problems if the filename contains more then one period. some of the filenames that I work with contain 5+ periods which throws the script off so I need look for the last period and then copy the characters after that. any help is greatly appreciated.

And here is what I have so far:

Code:
$filename = 'A10.300.jpg'; 

$filename =~ m/\.(.*)$/;

# currently $1 = 300.jpg
 
$filename = 'A10.300.jpg';

$filename =~ m/\.(\w+)$/;

# currently $1 = 300.jpg

or use the File::Basename module

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Slightly more complete regular expression

Code:
my $filename = 'A10.300.jpg';
$filename =~ m/\.([^\.]*)$/;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top