namishtiwari has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
#!/usr/bin/perl -w my $timestamp; my $line = "Fri May 29 18:29:57.357 2009 Morocco Standard Time INFO: p +id 3216 tid 1724: 170: 132192: apricocot Native Server: recvd AA_BIN_ +MSG_VER_CHG"; if ($line =~ /^(.*) INFO: .* recvd AA_BIN_MSG_VER_CHG/) { $timestamp = $1; print $timestamp; }
My regular expression the if statement is not correct, kindly help me in correcting it. Thanks NT

Replies are listed 'Best First'.
Re: regular expression problem
by binf-jw (Monk) on Jun 12, 2009 at 12:51 UTC
    You have an extra space between .* and recvd, using \s it reads .*\s\srecvd. You should use \s for spaces to avoid subtle errors like this.
    Also including /xms; is good as then you can add comments it forces you to use \s
    my $line = "Fri May 29 18:29:57.357 2009 Morocco Standard Time INFO: pid 32 +16 tid 1724: 170: 132192: apricocot Native Server: recvd AA_BIN_MSG_V +ER_CHG"; my $MATCH_TIMESTAMP = qr{ \A ( .*? ) # Capture time-stamp \s INFO: .*? recvd \s AA_BIN_MSG_VER_CHG }xms; if ( $line =~ $MATCH_TIMESTAMP ) { # Made timestamp lexical, you might not want that. print my $timestamp = $1; }


    J,
Re: regular expression problem
by planetscape (Chancellor) on Jun 12, 2009 at 12:25 UTC
Re: regular expression problem
by Corion (Patriarch) on Jun 12, 2009 at 12:18 UTC

    recvd AA_BIN_MSG_GET_WLT will never match recvd AA_BIN_MSG_VER_CHG.

      By Mistake i put that, I corrected it now. Thanks for pointing it out. Thanks NT
        Hi, Any help in correcting my regular expression match. Thanks NT