extract all after last period

Posted on 2009-03-31
Last Modified: 2012-05-06
retrieve everything after the last period
I'm in essence trying to retrieve the file extension
Question by:NewtonianB
  • 3
  • 2
LVL 40

Expert Comment

ID: 24035830

my $s = "test3.24.testing.233.txt";

my ($ext) = $s =~ /\.([^.]*)$/;

print "$ext\n";

Open in new window


Author Comment

ID: 24035883
great! what do the parenthesis signify, it doesn't work without them

Author Comment

ID: 24035885
the parenthesis around $ext
LVL 40

Accepted Solution

mrjoltcola earned 250 total points
ID: 24035899
The regex match operator =~ returns a matches in a list context.

my ($v1, $v2, $v3)   is a list
my $v1, $v2, $v3 is not a list, it is 3 scalars.

You can rewrite the whole thing if you want to:

if($s =~ /\.([^.]*)$/) {

   my $ext = $1;


Open in new window


Author Closing Comment

ID: 31565145

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl rename 2 142
How to delete rows in a file based on the file name. 5 53
Exchange 2010 Transport Rule Regex 28 95
Extract data from span tag 1 91
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now