CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [wattsup] Regex on filenames: Edit Log



FishMonger
Veteran / Moderator

Feb 23, 2016, 2:46 PM


Views: 2086
Re: [wattsup] Regex on filenames


Code
#!/usr/bin/perl 

use warnings;
use strict;

my @files = ('Sheehan Majestic P99975 S14166 SC2550.csv',
'WANG P YL63316 S142 SC2550.CSV',
'Wang PO YL63216 S14160 SC2550.csv');

foreach my $file (@files) {
if ($file =~ /(s\d+)\s(sc\d{4})\.csv$/i) {
print "$1\t$2$/";
}
}



Code
c:\test>Perl-1.pl 
S14166 SC2550
S142 SC2550
S14160 SC2550



(This post was edited by FishMonger on Feb 23, 2016, 2:48 PM)


Edit Log:
Post edited by FishMonger (Veteran) on Feb 23, 2016, 2:47 PM
Post edited by FishMonger (Veteran) on Feb 23, 2016, 2:48 PM
Post edited by FishMonger (Veteran) on Feb 23, 2016, 2:48 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives