🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #243254

Re: Dialog (regex defect): Action rule using "Header" scans into body of post

#243254
From: VanguardLH
Date: Tue, 16 Nov 2010 21:18
105 lines
6525 bytes
Tom B. wrote:

> VanguardLH wrote in "news.software.readers" ...
> 
> [trimmed]
>  
>> I'll give an easy example.  Open Dialog's regular expression tester.  In
>> regex field, enter:
>> 
>> (?-m)^Path: .+![^!]+\.othernsp\.com(!not-for-mail)?$
>> 
>> In the "match on" field, enter (as 3 lines):
>> 
>> Organization: me and mine
>> Path: news.mynsp.net!news.othernsp.com!not-for-mail
>> X-Complaints: abuse@report.othernsp.com
>> 
>> There is NO match.  I've told the regex to NOT use mutli-line mode and
>> that the test string is at the end of the line.  This is true but there
>> is no match.  Now change "(?-m)" to "(?m)" (or just remove this prefix
>> operator since multi-line mode is the default mode), so you have:
>> 
>> (?m)^Path: .+![^!]+\.othernsp\.com(!not-for-mail)?$
>> or
>> ^Path: .+![^!]+\.othernsp\.com(!not-for-mail)?$
>> 
>> There is now a match but it is greedy and extends beyond the Path header
>> line to the end of the X-Complaints header line (i.e., the match is
>> across multiple header values).  That's what I'm trying to avoid.
> 
> It may be the dot(s). I don't know how Marcus compiled the PCREs. I 
> assume Dialog was compiled with the PCRE_DOTALL option which means 
> the dot also matches newlines. In this case the ".+" means keep 
> searching, even across newlines, until the next stuff matches or it 
> fails at the end of the article. You could try keeping multi line 
> but unsetting DOTALL (or set it depending on the compiled option).
> 
> (?-s)  unsets DOTALL, and of course (?s) sets it (probably default)
>  
> [snip]
>  
>> The test string must be at the end of the header's value.  For now, I'll
>> settle for testing for the string at end of the SAME line as where the
>> header is identified.  The parsing must not extend beyond one line to
>> possibly find the test string in another line for a different header.
>> To make sure the string is at the end of the line, it appears that I
>> need to use the "$" anchor.  Yet this does NOT dictate that the
>> end-of-line character be in the same line as the header's title.  The
>> test string could be at the end of a subsequent line for a completely
>> different header.  The "(?-m)" operator only works if the entire test
>> text is comprised of a single line (and apparently which is not
>> terminated with \n) which will never be true for the headers section in
>> newsgroup posts.
>> 
>> So I'm still looking for a viable regex to look for the specified string
>> ONLY within the header that is identified, and possibly with that string
>> at the end of the line (for THAT specified header's value).
> 
> $ also has compiler options but I don't think there is an option 
> for the user. So in multi line mode you are probably stuck with $ 
> at end of subject - the whole article in multi line mode.
 
Doesn't work.  I tried the following:

regex:
(?-s)^Path: .+![^!]+\.othernsp\.com(!not-for-mail)?$

test text:
Organization: me and mine
Path: news.mynsp.net!news.othernsp.com!not-for-mail
X-Complaints: abuse@report.othernsp.com

There was a match but it spanned the Path and X-Complaints headers.
That is, the match was from the start of the Path header line to the end
of the X-Complaints header line.  I tried (?s) in case the switch was
reversed but that didn't help (didn't make any difference so it doesn't
appear the dotall option is ignored).

> Using "\r\n" instead of "$" may work (seems to work with Gravity's 
> PCREs). Or some other hack like "[^\w ]" (include the space). I 
> don't really know, I only tested them once.

I guess I'm still engrained in the old C programming style where \n
meant newline which could be \n or \r\n depending on the OS where the
end-of-line sequence was being added to the document.  So I figured on
Windows that \n meant the CR-LF sequence.  Well, according to the wiki
article at http://en.wikipedia.org/wiki/Newline, PCRE might still only
be using \n as the linefeed character.

I replace the $ trailing anchor (for end-of-line) with \r\n, as in:

^Path: .+![^!]+\.othernsp\.com(!not-for-mail)?\r

This worked to match on just the trailing text in the same line as where
the Path header is defined.  I didn't even need the (?-s) operator
(which doesn't seem implemented in Dialog).  \r\n also worked at the end
of the Path header to delimit the parsing to just that line.  While the
\n (linefeed, not the newline that I'm used to from C) is used in
Windows, it isn't required on other OS platforms to denote the
end-of-line marker.  So hopefully just \r is all I need to use in
replacing the $ anchor.

I'll have to review all my rules to see where any greedy operators are
used and check if I have to replace the trailing $ anchor, if used, with
\r or \r\n.
Technical Details
Message-ID: <ibuse3$g7b$1@news.albasani.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.albasani.net!not-for-mail
References: <ibieuc$fa1$1@news.albasani.net> <4jnelelbf8ic.dlg@mid.crommatograph.info> <ibrutm$26h$1@news.albasani.net> <ibt23d$lq6$1@news.albasani.net> <MPG.274c0684271c22009896b2@news.individual.net>

Show Full Headers
Complete Article Headers
Message-ID: <ibuse3$g7b$1@news.albasani.net>
Subject: Re: Dialog (regex defect): Action rule using "Header" scans into body of post
Date: Tue, 16 Nov 2010 15:18:09 -0600
From: VanguardLH <V@nguard.LH>
References: <ibieuc$fa1$1@news.albasani.net> <4jnelelbf8ic.dlg@mid.crommatograph.info> <ibrutm$26h$1@news.albasani.net> <ibt23d$lq6$1@news.albasani.net> <MPG.274c0684271c22009896b2@news.individual.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.albasani.net!not-for-mail
Newsgroups: news.software.readers
Organization: 0.35MOA sniper at loose in Usenet
Lines: 105
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.albasani.net
 iygcIZ/cYLVqVQKfO58g4ddYlPKOUm8cU2pixME+z2GCAd2gSqGDPO08t7S7St382Cy6vlxdVvHOuctsTwhfSKTXIAJh9keLN7Jo+u7Enxv3rMjWHOy2GvLnWQq56XWO
NNTP-Posting-Date: Tue, 16 Nov 2010 21:17:55 +0000 (UTC)
Keywords: VanguardLH VLH811
Cancel-Lock: sha1:UK/C+kc99vvIr1VL1CbLDkc8fpA=
User-Agent: 40tude_Dialog/2.0.15.41
Injection-Info: news.albasani.net;
 logging-data="dHNXwGbnBYN+HWspL6VVyYgcPAEbqIW9c+xf8VL4B+VQyI/FuC5aDtkzWAnJqigJdKVTmpE1TIehInf2sq0MauooGr0w2rAN3wlYuNtMCmD9Bjr9BjFsbhHMJOLEwy96";
 mail-complaints-to="abuse@albasani.net"
X-MOTD: It is wiser to remain silent and let others ponder your ignorance than
 to speak and remove all doubt
X-Original-Bytes: 6267