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&#39;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&#39;ve tried:</=
div><div>-----------------------------------------<br></div><div>1:</div><d=
iv>(($self-&gt;TicketObj-&gt;Subject =3D~ /Cron \&lt;root\@pbx\&gt; \/etc\/=
init\.d\/asterisk restart/) &amp;&amp; # Successful cron jobs.</div><div>($=
self-&gt;TicketObj-&gt;Body =3D~ /\* Starting Asterisk PBX\: asterisk\n\.\.=
\.done\./m)<br></div><div><div><br></div><div>2:</div><div>(($self-&gt;Tick=
etObj-&gt;Subject =3D~ /Cron \&lt;root\@pbx\&gt; \/etc\/init\.d\/asterisk r=
estart/) &amp;&amp; # Successful cron jobs.</div><div><span class=3D"gmail-=
Apple-tab-span" style=3D"white-space:pre">	</span>($self-&gt;TicketObj-&gt;=
Body =3D~ /\* Starting Asterisk PBX\: asterisk.*\.\.\.done\./ms))<br></div>=
</div><div>3:</div><div><div>(($self-&gt;TicketObj-&gt;Subject =3D~ /Cron \=
&lt;root\@pbx\&gt; \/etc\/init\.d\/asterisk restart/) &amp;&amp; # Successf=
ul cron jobs.</div><div><span class=3D"gmail-Apple-tab-span" style=3D"white=
-space:pre">	</span>($self-&gt;TicketObj-&gt;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">&lt;<a href=3D"mailto:[email protected]" targ=
et=3D"_blank">[email protected]</a>&gt;</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 &lt;<a href=3D"mailto:[email protected]"=
>[email protected]</a>&gt; wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I&#39;m trying to automatically resolve tickets that don&#39;t require=
 any action.<br>
&gt; In this example, I receive a backup notification. I know it&#39;s a ba=
ckup<br>
&gt; script result email based on the subject, and I know the backup was<br=
>
&gt; successful (and therefore I can auto-resolve the ticket) if another re=
gex<br>
&gt; matches the body. When I match against the subject line alone, it work=
s.<br>
&gt; However, when I try to match against the mutli-line body, it never mat=
ches<br>
&gt; (even though when I run the regex against the string in a test, it mat=
ches<br>
&gt; as expected).<br>
&gt;<br>
&gt; 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>
&quot;&quot;&quot;<br>
Modifier m<br>
<br>
Treat the string as multiple lines. That is, change &quot;^&quot; and &quot=
;$&quot; from<br>
matching the start of the string&#39;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>
&quot;&quot;&quot;<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&#39;s &quot;Perl Best Practices&quot; 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==--