develooper Front page | perl.beginners | Postings from February 2009

Re: regarding regular expression

Thread Previous
From:
itshardtogetone
Date:
February 27, 2009 20:06
Subject:
Re: regarding regular expression
Message ID:
COL0-DAV21E24349FCE4235876FB49B7AB0@phx.gbl
----- Original Message ----- 
From: "John W. Krahn" <jwkrahn@shaw.ca>
To: "Perl Beginners" <beginners@perl.org>
Sent: Thursday, February 26, 2009 10:54 PM
Subject: Re: regarding regular expression


> Irfan Sayed wrote:
>> Hi All,
> 
> Hello,
> 
>> I have a string like this "pqp-un_1.0G_2009-02-23_17-38-09_5678903.txt
>> " now what i need is only all digits before .txt till first underscore.
>>  
>> which means i need only output as 5678903

or try this

#!/usr/bin/perl
use strict;
use warnings;

my $a = 'pqp-un_1.0G_2009-02-23_17-38-09_5678903.txt';

if ($a =~/_(\d+)\.txt/){
 print "The wanted digits = $1\n";
}else{
 print "unmatch\n";
}


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About