[rt-users] Regex in scrip won't match multi-line strings
Peter Nikolaidis
petern at paradigmcc.com
Fri Mar 3 10:30:02 EST 2017
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?
Thanks,
Peter
On Mon, Feb 27, 2017 at 10:57 AM, Matt Zagrabelny <mzagrabe at d.umn.edu>
wrote:
> On Mon, Feb 27, 2017 at 9:48 AM, Peter Nikolaidis <petern at paradigmcc.com>
> wrote:
> > Hi all,
> >
> > I'm trying to automatically resolve tickets that don't require any
> action.
> > In this example, I receive a backup notification. I know it's a backup
> > script result email based on the subject, and I know the backup was
> > successful (and therefore I can auto-resolve the ticket) if another regex
> > matches the body. When I match against the subject line alone, it works.
> > However, when I try to match against the mutli-line body, it never
> matches
> > (even though when I run the regex against the string in a test, it
> matches
> > as expected).
> >
> > Are multi-line matches not an option, or do I need to test in another
> way?
>
> From:
>
> http://perldoc.perl.org/perlre.html
>
> """
> Modifier m
>
> Treat the string as multiple lines. That is, change "^" and "$" from
> matching the start of the string's first line and the end of its last
> line to matching the start and end of each line within the string.
> """
> I almost always use /xms for my REs. This allows for significant
> readability - at the cost of significant number of lines. Check out
> Damian Conway's "Perl Best Practices" Regular Expression chapter.
>
> -m
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20170303/aa7683c7/attachment.htm>
More information about the rt-users
mailing list