in reply to regular expression issue

Please use the <code>...</code> tags around perl code - it makes it a lot easier to read.

Not knowing what kind of variation there could be in other messages of this type, I would take the following conservative approach to parsing it:

if (m/Reply issued by (.*?):(.*)/) { my $issuer = $1; my $msg = $2; if ($issuer =~ m/([^\\]+)@/) { $issuer = $1; } $msg =~ s/\A\s*'\(ACK\)\s*//; $msg =~ s/\s*'\s*\z//; # results are in $issuer and $msg } else { # not a Reply issued by message }
The idea is to match the issuer and message sections and then trim each appropriately. If there happen to be similar messages which don't conform exactly to this format, at least you'll get something back.

Update: Changed \a in regex to \A - thanks moritz!

Replies are listed 'Best First'.
Re^2: regular expression issue
by sumesh.sasi (Initiate) on Jun 06, 2008 at 08:11 UTC
    Hello, I am not getting what I want. I extracted the out put from the first part ie.
    if (m/Reply issued by (.*?):(.*)/) { my $issuer = $1; my $msg = $2; print " $issuer \n $msg \n"; }
    the $issuer is as below, you can see the \b interpreted as regex \b. ASlrssrajSRVPARTSP3930 is the Out put
      In a double-quoted string, the sequence  "\b" is a backspace control code. See following examples in double- and single-quoted strings.

      perl -wMstrict -e "my $s = qq(abcdX\befg); print $s" abcdefg perl -wMstrict -e "my $s = qq(abcdX \befg); print $s" abcdXefg perl -wMstrict -e "my $s = q(abcdX\befg); print $s" abcdX\befg perl -wMstrict -e "my $s = q(abcdX \befg); print $s" abcdX \befg

      See Quote and Quote like Operators in perlop.

        Thanks, Thats perfect. Good to know that difference.I was using the double quoted string, that causes the problem Thanks alot