in reply to Regular expression

Also in the chatterbox, I pointed out File::Basename and File::Spec to you. Both will only work for your filenames if you're on Win32. If you're trying this on a non-Windows platform, the mentioned alternative of using /([^\\+])$//([^\\]+)$/ to extract the filename part will still work, with the minor change of using whitespace instead of end of line as the anchor.

Personally, I would approach your log parsing task by splitting on whitespace and then looking closer at the filename part:

my @entries = split "", $record; if ($record[0] eq 'FRAG') { warn "File is $record[8]"; $record[8] =~ /([^\\+])$/ or die "Malformed file entry: '$record[8]'"; warn "Basename is '$1'"; };

Update: Fixed bad typo that rendered the RE useless.

Replies are listed 'Best First'.
Re^2: Regular expression
by PugSA (Beadle) on Sep 16, 2008 at 13:38 UTC

    I'm on a Solaris machine and tried ([^\\+]) but can't match it at end of line thats why I posted the code here I'll try the split Thank you

      You could use File::Basename, split and tr:

      use File::Basename; $record = "FRAG 1 1 2000000 0 0 0 0 \\\\172.20.13.49\\backup\\rbgmst02 +_dd2\\stu1\\CPOSTA_1221170039_C1_F1 rbgmst02 65536 0 0 -1 0 *NULL* 12 +22379639 1 65537 0 0 0 0 0 0 0"; if($record =~ m|FRAG|) { my $str = (split " ", $record)[8]; $str =~ tr[\\][/]; print basename($str),"\n"; } __END__ CPOSTA_1221170039_C1_F1

      Alternative:

      $record = "FRAG 1 1 2000000 0 0 0 0 \\\\172.20.13.49\\backup\\rbgmst02 +_dd2\\stu1\\CPOSTA_1221170039_C1_F1 rbgmst02 65536 0 0 -1 0 *NULL* 12 +22379639 1 65537 0 0 0 0 0 0 0"; if($record =~ m|FRAG|) { $record =~ /(?<=\\)(\w+)(?:\s|$)/; print "$1\n"; } __END__ CPOSTA_1221170039_C1_F1

      See perlre.