Solved

extract all after last period

Posted on 2009-03-31
5
225 Views
Last Modified: 2012-05-06
retrieve everything after the last period
test3.24.testing.233.txt
I'm in essence trying to retrieve the file extension
0
Comment
Question by:NewtonianB
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24035830

my $s = "test3.24.testing.233.txt";
my ($ext) = $s =~ /\.([^.]*)$/;
 
print "$ext\n";

Open in new window

0
 

Author Comment

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

Author Comment

by:NewtonianB
ID: 24035885
the parenthesis around $ext
0
 
LVL 40

Accepted Solution

by:
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

0
 

Author Closing Comment

by:NewtonianB
ID: 31565145
thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

756 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