[rt-users] Regex in scrip won't match multi-line strings
Matt Zagrabelny
mzagrabe at d.umn.edu
Fri Mar 3 10:46:05 EST 2017
On Fri, Mar 3, 2017 at 9:30 AM, Peter Nikolaidis <petern at paradigmcc.com> wrote:
> Apparently I'm still doing something wrong and regex is kicking my butt.
>
> Sample message body:
> -----------------------------------------
> * Stopping Asterisk PBX: asterisk
> ...done.
> * Starting Asterisk PBX: asterisk
> ...done.
> -----------------------------------------
>
> Patterns I've tried:
> -----------------------------------------
> 1:
> (($self->TicketObj->Subject =~ /Cron \<root\@pbx\> \/etc\/init\.d\/asterisk
> restart/) && # Successful cron jobs.
> ($self->TicketObj->Body =~ /\* Starting Asterisk PBX\:
> asterisk\n\.\.\.done\./m)
>
> 2:
> (($self->TicketObj->Subject =~ /Cron \<root\@pbx\> \/etc\/init\.d\/asterisk
> restart/) && # Successful cron jobs.
> ($self->TicketObj->Body =~ /\* Starting Asterisk PBX\:
> asterisk.*\.\.\.done\./ms))
> 3:
> (($self->TicketObj->Subject =~ /Cron \<root\@pbx\> \/etc\/init\.d\/asterisk
> restart/) && # Successful cron jobs.
> ($self->TicketObj->Body =~ /^\* Starting Asterisk PBX\:
> asterisk.*\.\.\.done\.$/ms)) ||
> -----------------------------------------
>
> Any ideas?
#!/usr/bin/perl
use strict;
use warnings;
my $sample_message_body = <<EOF;
* Stopping Asterisk PBX: asterisk
...done.
* Starting Asterisk PBX: asterisk
...done.
EOF
my $sample_message_body_2 = <<EOF;
* Stopping Asterisk PBX: asterisk.
...done.
* Starting Asterisk PBX: asterisk.
...done.
EOF
my $re = qr{
^\*\s+Stopping\s+Asterisk\s+PBX:\s+asterisk$
\n
^\.\.\.done\.$
\n
^\*\s+Starting\s+Asterisk\s+PBX:\s+asterisk$
\n
^\.\.\.done\.$
}xms;
if ($sample_message_body =~ $re) {
print "MATCHES!\n";
}
else {
print "NOPE!\n";
}
if ($sample_message_body_2 =~ $re) {
print "MATCHES!\n";
}
else {
print "NOPE!\n";
}
-m
More information about the rt-users
mailing list