Brian268 has asked for the wisdom of the Perl Monks concerning the following question:
Hi I'm trying to understand regurlar exprresions in the folowing only one works (merilyn14) every thing else comes out in FoxyM and i'm not sure why can you help?
In print staitmets give the example of what i'm exspecting
#!/usr/bin/perl @Files =( "filename=merilyn14.jpg.jpeg", "filename=003_Merilyn23.jpg.jpeg", "filename=890FoxyM.jpg.jpeg", "filename=006.jpg.jpeg" ); foreach my $file (@Files) { if ($file =~ m/filename=(\d.*?)([a-zA-Z].*?)\.j/i) { $nFold =$2; $nFile = $1 . $2 . ".jpg"; print "FoxyM New fold = $nFold file = $nFile\n"; } elsif ($file =~ m/filename=([a-zA-Z].*?)(\d.*)\.j/i) { $nFold =$1; $nFile = $1 . $2 . ".jpg"; print "merilyn14 New fold = $nFold file = $nFile\n"; } elsif ($file =~ m/filename=(\d.*?)_([a-zA-Z].*)(\d.*?)\.j/i) { $nFold =$1 ."_" . $2; $nFile = $1 ."_" . $2 . $3 . ".jpg"; print "003_Merilyn23 New fold = $nFold file = $nFile\n"; } elsif ($file =~ m/filename=(\d.*?)\.j/i) { $nFold ="FileNum"; $nFile = $1 . ".jpg"; print "006 New fold = $nFold file = $nFile\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RegEx Help
by BrowserUk (Patriarch) on Dec 17, 2011 at 12:34 UTC | |
|
Re: RegEx Help
by ww (Archbishop) on Dec 17, 2011 at 21:10 UTC | |
by Anonymous Monk on Dec 20, 2011 at 14:54 UTC | |
by ww (Archbishop) on Dec 20, 2011 at 17:21 UTC | |
|
Re: RegEx Help
by pvaldes (Chaplain) on Dec 17, 2011 at 18:35 UTC | |
by ww (Archbishop) on Dec 17, 2011 at 22:11 UTC | |
by pvaldes (Chaplain) on Dec 19, 2011 at 00:11 UTC | |
by Anonymous Monk on Dec 20, 2011 at 14:49 UTC | |
by ww (Archbishop) on Dec 20, 2011 at 17:18 UTC | |
|
Re: RegEx Help
by TJPride (Pilgrim) on Dec 17, 2011 at 16:11 UTC |