Home: Perl Programming Help: Beginner:
regular expression



shinyhui
New User

Dec 5, 2012, 7:15 PM


Views: 2191
regular expression

i've a list of files

Quote
ABC1.txt
ABC1a_1.txt
ABC1a_1_1.txt
ABC1b.txt
ABC1b_1.txt
ABC11.txt
ABC1.png


what the regex i should use where only these 4 files is list


Quote
ABC1.txt
ABC1a_1.txt
ABC1a_1_1.txt
ABC1b.txt
ABC1b_1.txt



BillKSmith
Veteran

Dec 5, 2012, 7:54 PM


Views: 2189
Re: [shinyhui] regular expression


Code
use strict; 
use warnings;
my @files = (
'ABC1.txt',
'ABC1a_1.txt',
'ABC1a_1_1.txt',
'ABC1b.txt',
'ABC1b_1.txt',
'ABC11.txt',
'ABC1.png',
);

my @special_files = grep {/ABC1(:?a_1|a_1_1|b|b_1)?\.txt/} @files;
print "@special_files\n";

Good Luck,
Bill


shinyhui
New User

Dec 5, 2012, 9:47 PM


Views: 2187
Re: [BillKSmith] regular expression

what about do not accept pattern [0-9]?