in reply to Perl file name parsing - Regular expression
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl file name parsing - Regular expression
by rinkish85 (Novice) on May 30, 2017 at 06:28 UTC | |
by Laurent_R (Canon) on May 30, 2017 at 08:20 UTC |