Re: Regex in scrip won't match multi-line strings
Peter Nikolaidis <[email protected]> Fri, 3 Mar 2017 10:30:02 -0500
| Newsgroups | gmane.comp.bug-tracking.request-tracker.user |
|---|---|
| Message-ID | <CACiQX-on-hUD4aq5wX8fkAs9UOFdTQC8U3q0McM1LA2ppZKY=w@mail.gmail.com> |
--===============0531928411== Content-Type: multipart/alternative; boundary=94eb2c19da3e904a790549d53a41 --94eb2c19da3e904a790549d53a41 Content-Type: text/plain; charset=UTF-8 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 <[email protected]> wrote: > On Mon, Feb 27, 2017 at 9:48 AM, Peter Nikolaidis <[email protected]> > 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 > --94eb2c19da3e904a790549d53a41 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Apparently I'm still doing something wrong and regex i= s kicking my butt.=C2=A0<div><br></div><div>Sample message body:</div><div>= -----------------------------------------<br></div><div><span style=3D"colo= r:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:13px">* Stopp= ing Asterisk PBX: asterisk</span><br style=3D"color:rgb(0,0,0);font-family:= arial,helvetica,sans-serif;font-size:13px"><span style=3D"color:rgb(0,0,0);= font-family:arial,helvetica,sans-serif;font-size:13px">...done.</span><br s= tyle=3D"color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:1= 3px"><span style=3D"color:rgb(0,0,0);font-family:arial,helvetica,sans-serif= ;font-size:13px">* Starting Asterisk PBX: asterisk</span><br style=3D"color= :rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:13px"><span st= yle=3D"color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:13= px">...done.</span><br></div><div>-----------------------------------------= <span style=3D"color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font= -size:13px"><br></span></div><div><br></div><div>Patterns I've tried:</= div><div>-----------------------------------------<br></div><div>1:</div><d= iv>(($self->TicketObj->Subject =3D~ /Cron \<root\@pbx\> \/etc\/= init\.d\/asterisk restart/) && # Successful cron jobs.</div><div>($= self->TicketObj->Body =3D~ /\* Starting Asterisk PBX\: asterisk\n\.\.= \.done\./m)<br></div><div><div><br></div><div>2:</div><div>(($self->Tick= etObj->Subject =3D~ /Cron \<root\@pbx\> \/etc\/init\.d\/asterisk r= estart/) && # Successful cron jobs.</div><div><span class=3D"gmail-= Apple-tab-span" style=3D"white-space:pre"> </span>($self->TicketObj->= Body =3D~ /\* Starting Asterisk PBX\: asterisk.*\.\.\.done\./ms))<br></div>= </div><div>3:</div><div><div>(($self->TicketObj->Subject =3D~ /Cron \= <root\@pbx\> \/etc\/init\.d\/asterisk restart/) && # Successf= ul cron jobs.</div><div><span class=3D"gmail-Apple-tab-span" style=3D"white= -space:pre"> </span>($self->TicketObj->Body =3D~ /^\* Starting Asteri= sk PBX\: asterisk.*\.\.\.done\.$/ms)) ||=C2=A0</div></div><div>------------= -----------------------------<br></div><div><br></div><div>Any ideas?</div>= <div><br></div><div>Thanks,</div><div><br>Peter</div><div class=3D"gmail_ex= tra"><br><div class=3D"gmail_quote">On Mon, Feb 27, 2017 at 10:57 AM, Matt = Zagrabelny <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" targ= et=3D"_blank">[email protected]</a>></span> wrote:<br><blockquote class= =3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg= b(204,204,204);padding-left:1ex"><span class=3D"gmail-">On Mon, Feb 27, 201= 7 at 9:48 AM, Peter Nikolaidis <<a href=3D"mailto:[email protected]"= >[email protected]</a>> wrote:<br> > Hi all,<br> ><br> > I'm trying to automatically resolve tickets that don't require= any action.<br> > In this example, I receive a backup notification. I know it's a ba= ckup<br> > script result email based on the subject, and I know the backup was<br= > > successful (and therefore I can auto-resolve the ticket) if another re= gex<br> > matches the body. When I match against the subject line alone, it work= s.<br> > However, when I try to match against the mutli-line body, it never mat= ches<br> > (even though when I run the regex against the string in a test, it mat= ches<br> > as expected).<br> ><br> > Are multi-line matches not an option, or do I need to test in another = way?<br> <br> </span>From:<br> <br> <a href=3D"http://perldoc.perl.org/perlre.html" rel=3D"noreferrer" target= =3D"_blank">http://perldoc.perl.org/<wbr>perlre.html</a><br> <br> """<br> Modifier m<br> <br> Treat the string as multiple lines. That is, change "^" and "= ;$" from<br> matching the start of the string's first line and the end of its last<b= r> line to matching the start and end of each line within the string.<br> """<br> I almost always use /xms for my REs. This allows for significant<br> readability - at the cost of significant number of lines. Check out<br> Damian Conway's "Perl Best Practices" Regular Expression chap= ter.<br> <span class=3D"gmail-HOEnZb"><font color=3D"#888888"><br> -m<br> </font></span></blockquote></div><div class=3D"gmail_signature"><div dir=3D= "ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><= div dir=3D"ltr"><div dir=3D"ltr"><br></div></div></div></div></div></div></= div></div> </div></div> --94eb2c19da3e904a790549d53a41-- --===============0531928411== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --------- RT 4.4 and RTIR Training Sessions https://bestpractical.com/training * Paris - April 24-26, 2017 --===============0531928411==--