Hello rinkish85,
I think the following does what you want:
use strict; use warnings; use feature 'say'; my @files = ( 'log4perl.Advanced1999:06:56:12.General_Information.ErrorLog', 'log4perl.Advanced1999:06:56:12CSS.General_Information-collector-2 +.ErrorLog', 'log4perl.Advanced1999:06:56:12CSS.General_Information-collector-2 +.INVALID', ); for (@files) { if (/ ^ [\w_-]+ \. [\w:]+ \. [\w_-]+ \. ErrorLog $ /x) { s/ ^ ([\w_-]+) \. ([\w:]+) CSS \. /$1.$2./x; say; } }
Output:
13:43 >perl 1783_SoPW.pl log4perl.Advanced1999:06:56:12.General_Information.ErrorLog log4perl.Advanced1999:06:56:12.General_Information-collector-2.ErrorLo +g 13:43 >
See perlrecharclass.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Perl file name parsing - Regular expression
by Athanasius
in thread Perl file name parsing - Regular expression
by rinkish85
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |