🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
11 messages
11 total messages Started by VanguardLH Fri, 12 Nov 2010 04:14
Dialog (regex defect): Action rule using "Header" scans into body of post
#243232
Author: VanguardLH
Date: Fri, 12 Nov 2010 04:14
94 lines
6207 bytes
40tude Dialog
2.0.15.41 (beta 38)

Objective: Ignore a post if it came from a leech site (i.e., a web-based
forum running a web-to-NNTP gateway to Usenet so the forum can pretend
it has a larger audience or to provide a webnews-for-boobs interface to
Usenet).

Action rule:

!ignore,markread Header {^User-Agent: .*\b(gateway|NewsPortal|PHP)\b.*$}

Originally I did not have the ".*$" at the end of the regex since I
figured it parsed to the end of the line or to the end of the value for
a header (i.e., it stopped parsing when it either hit another header
line or the blank delimiter line).  Wrong, as I found out and noted
below.  However, adding the trailing "$" to denote the end of line does
not restrict the parsing to just the same line as where the header title
string is found.

Expected result:
- Header does not exist.  Rule does not fire.
- Header exists.  No match on regex for its value.  Rule does not fire.
- Header exists.  Match on regex for its value.  Rule fires.

Problem:
The "Header" operator does NOT restrict the parsing to only the header
section of the article.  It scans through the ENTIRE article, including
the body.

Any scanning of headers for values should be restricted to only the
header section of an article.  The body should NOT be included.  Per
RFC, the header and body are separated by the first blank line in the
article.  That is, the header ends at the first \n\n sequence (newline
at the end of the last header line and the newline for the blank
delimiter line).

Since the action rule using "Header" ends up scanning beyond the header
section and wanders off into the body section, anything in the body that
is in the regex ends up completing a True for the test.  I'll give an
example below (shown between the equal-sign delimiter lines):

==============================
From: someone <email@domain.tld>
Newsgroup: <pickone>
<moreHeaders>
User-Agent: Mozilla(yadda...yadda...yadda...
<moreHeaders>

First line (after blank delimiter line) of body.  User want drivers for
a Gateway model and need drivers for an old version of Windows.
==============================

>From the action rule given above, it should NOT fire.  There is no
"gateway", "newsportal", or "php" words in the value for the User-Agent
header.  But what does Dialog do?  It matches all the way from the
"User-Agent" header title in the header section, past the blank
delimiter line and into the body to end its match at the end of the
"Gateway" word in the body.  

Obviously I'm not trying to test on header values that are strings down
in the body of the article!  There are *no* headers past the blank
delimiter line and their values, even for multi-line values, do not
extend beyond that blank delimiter line.

When testing on a header value, parsing should stop at either the first
occurrence of \n\n (the blank line) or the next occurrence of ^\w+: (the
next header title which is always positioned at the start of a line
versus continuation lines that have leading spaces).

The use of Header in an action rule seems to look for that string to
appear anywhere in the article, including in the body, and also of
parsing its value off into the body section.  I'm accustomed to using
the greedy versions of regex so maybe I need to think how to code the
regex to be non-greedy so somehow it cannot extend beyond a single line.
Since the .* seems to be what might be causing the parsing to continue
beyond the end of line (although I've tried using the $ end-of-line
character at the end of the regex), just how would I specify to look
within one line for a string (on a word boundary since I'm looking for
full words, not substrings)?  While some headers can be multi-line, none
of those on which I test are that long.

Besides the Header operator, I have to wonder how many other posts have
been incorrectly tagged because parsing of the regex extended beyond the
the actual value of the named header.  Maybe the From, Message-ID,
X-Ref, and other preset operators identifying headers are similarly
screwed up and end up testing the regex outside the value for the
specified header, extending into the values of other following headers,
and even into the body.  Hopefully not and only the parsing of the
Header operator is screwed up; however, I have many action rules defined
that test on non-overview headers (since that is often the only way to
track a poster or source).  That's why I have Dialog download the entire
article so I can test on all the headers.  Takes longer to get Dialog
updated but then I only visit text-only groups and no binary groups.
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243241
Author: Oliver Cromm
Date: Mon, 15 Nov 2010 17:12
61 lines
3928 bytes
* VanguardLH:

> Action rule:
> 
> !ignore,markread Header {^User-Agent: .*\b(gateway|NewsPortal|PHP)\b.*$}
> 
> Originally I did not have the ".*$" at the end of the regex since I
> figured it parsed to the end of the line or to the end of the value for
> a header (i.e., it stopped parsing when it either hit another header
> line or the blank delimiter line).  Wrong, as I found out and noted
> below.  However, adding the trailing "$" to denote the end of line does
> not restrict the parsing to just the same line as where the header title
> string is found.
> 
> Expected result:
> - Header does not exist.  Rule does not fire.
> - Header exists.  No match on regex for its value.  Rule does not fire.
> - Header exists.  Match on regex for its value.  Rule fires.
> 
> Problem:
> The "Header" operator does NOT restrict the parsing to only the header
> section of the article.  It scans through the ENTIRE article, including
> the body.

[...] 

> ==============================
> From: someone <email@domain.tld>
> Newsgroup: <pickone>
> <moreHeaders>
> User-Agent: Mozilla(yadda...yadda...yadda...
> <moreHeaders>
> 
> First line (after blank delimiter line) of body.  User want drivers for
> a Gateway model and need drivers for an old version of Windows.
> ==============================
> 
> From the action rule given above, it should NOT fire.  There is no
> "gateway", "newsportal", or "php" words in the value for the User-Agent
> header.  But what does Dialog do?  It matches all the way from the
> "User-Agent" header title in the header section, past the blank
> delimiter line and into the body to end its match at the end of the
> "Gateway" word in the body.  

I tested this specific example, and the rule did not fire for me. Are
you sure that there wasn't a match anywhere in the Header below the
User-Agent line?

In any case, the solution to your problem should be turning off
multi-line matching with (?-m):

 !ignore,markread Header {(?-m)^User-Agent: .*\b(gateway|NewsPortal|PHP)\b.*$}

I remember my initial confusion because the standard parameters for
RegEx in Scoring are ignore-case and match-multiline. So just in case,
also remember (?-i), the parameter to make the match case-sensitive.

-- 
dasz jederman sehe, wie falsch unsere gugelmönche zu ihres ordens
verteidigung der ersten kirchenexempel anziehen Calvin
  GRIMM, Deutsches Wörterbuch
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243243
Author: VanguardLH
Date: Mon, 15 Nov 2010 18:42
101 lines
6312 bytes
Oliver Cromm wrote:

> * VanguardLH:
> 
>> Action rule:
>> 
>> !ignore,markread Header {^User-Agent: .*\b(gateway|NewsPortal|PHP)\b.*$}
>> 
>> Originally I did not have the ".*$" at the end of the regex since I
>> figured it parsed to the end of the line or to the end of the value for
>> a header (i.e., it stopped parsing when it either hit another header
>> line or the blank delimiter line).  Wrong, as I found out and noted
>> below.  However, adding the trailing "$" to denote the end of line does
>> not restrict the parsing to just the same line as where the header title
>> string is found.
>> 
>> Expected result:
>> - Header does not exist.  Rule does not fire.
>> - Header exists.  No match on regex for its value.  Rule does not fire.
>> - Header exists.  Match on regex for its value.  Rule fires.
>> 
>> Problem:
>> The "Header" operator does NOT restrict the parsing to only the header
>> section of the article.  It scans through the ENTIRE article, including
>> the body.
> 
> [...] 
> 
>> ==============================
>> From: someone <email@domain.tld>
>> Newsgroup: <pickone>
>> <moreHeaders>
>> User-Agent: Mozilla(yadda...yadda...yadda...
>> <moreHeaders>
>> 
>> First line (after blank delimiter line) of body.  User want drivers for
>> a Gateway model and need drivers for an old version of Windows.
>> ==============================
>> 
>> From the action rule given above, it should NOT fire.  There is no
>> "gateway", "newsportal", or "php" words in the value for the User-Agent
>> header.  But what does Dialog do?  It matches all the way from the
>> "User-Agent" header title in the header section, past the blank
>> delimiter line and into the body to end its match at the end of the
>> "Gateway" word in the body.  
> 
> I tested this specific example, and the rule did not fire for me. Are
> you sure that there wasn't a match anywhere in the Header below the
> User-Agent line?

Ah, I checked (I use a clipboard manager so I could go find the copy of
the problematic post, headers and body, that I snipped before).  You're
right.  There was an occurrence of "gateway" in another header.  The
Subject header had "Cannot install Windows XP 32-bit on my Gateway ...".
In this case, the User-Agent header was positioned before the Subject
header hence why my action rule fired accidentally.  For some reason, my
eyes saw what I only wanted to see and that didn't include looking at
the content of the Subject header.  DOH!

> In any case, the solution to your problem should be turning off
> multi-line matching with (?-m):
> 
>  !ignore,markread Header {(?-m)^User-Agent: .*\b(gateway|NewsPortal|PHP)\b.*$}

Thanks for that info.  While I use regex often, there is still a ton of
it that I don't know.  Sometimes it just boggles my mind too much when I
start digging into PCRE as to just how complicated you can make the
expressions.  I'll see if your suggestion works to force the regex to
search only on one line.  I had assumed that was the default but looks
like I was wrong.

> I remember my initial confusion because the standard parameters for
> RegEx in Scoring are ignore-case and match-multiline. So just in case,
> also remember (?-i), the parameter to make the match case-sensitive.

Yeah, I found out about the default of case-insensitive searching but it
makes the typical regex easier to compose.  I have a couple rules where
I use it, as in:

^(Re:\s*)?(?-i)[^a-z]*$

where I am checking if the poster (in a starter post or in a reply) had
no lowercase alphanumeric characters in the Subject header, like it was
all uppercase (i.e., they're screaming) and/or non-alphabetic characters
(i.e., all digits, dollar signs, parens, etc.).

The default of case-insensitive matches I knew about and understand why
that is the default.  I didn't realize the Header search spanned
multiple lines but then thinking about it then that is probably a
requirement since header values often span more than one line, like the
Received header; however, it wouldv'e made a lot more sense to terminate
a search on the specified header when the \n\n was found (marking the
end of the headers section) or when the next header title was found
(starts at byte 1 in a line with no spaces in the title and following
within whitespace with a colon character).  But then there is no
InHeaders operator to specify looking anywhere in any header and across
headers (i.e., a substring match on all text in all headers).

Thanks for the heads up on the multi-line prefix for regex.  Something
new I learned.  Hopefully I won't later run across a User-Agent header
that is so long that it uses multiple lines.
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243246
Author: VanguardLH
Date: Tue, 16 Nov 2010 04:43
78 lines
5440 bytes
Well, that almost worked.  If I include the "(?-m)" operator then I have
to remove the trailing "$" anchor in the regex.  For example, say the
Path header has (it's been shortened here to show on one line just as it
was in the post):

Path: news.mynsp.net!host.othernsp.com!not-for-mail

If the regex is:

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

then there is a match; however, as discovered, this match might span
multiple lines which means I might be getting the last part of the
string from a different header.  So I added the "(?-m)" as follows:

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

So now the regex looks for a matching string on just one line.  Yet I
get no match.  I have to remove the trailing "$" end-of-line anchor at
the end of the regex.  Well, yeah, I then get a match but now the regex
is not guaranteeing that the string is at the *end* of the line.

The problem is that the text being tested will very well have multiple
lines (there are many lines for all the headers).  If I paste in the
Path header's value in one line (not even a following blank line) then
there is a match.  But there will be more than one line in the headers
section.  As soon as I add a block of headers to see if the regex works,
there is no match.  So it seems the (?-m) doesn't restrict the parsing
to one line but requires the entire test string to be on only 1 line
which won't happen with headers in posts.

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.

If I don't use the "(?-m)" operator, there is a match but it can extend
to multiple lines.  This means the test string might not be in the
header that you specified but contained in a following header's value.
If I do use the "(?-m)" operator, there is no match despite that the
test string is most definitely to be found in the one line for the Path
header.

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).
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243244
Author: Tom B.
Date: Tue, 16 Nov 2010 08:10
68 lines
4256 bytes
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.

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.

-- 
Tom B.      * * * Gravity Web Pages  * * *
http://mpgravity.sourceforge.net/ (official site)
http://gravity.tbates.org/
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243247
Author: Tom B.
Date: Tue, 16 Nov 2010 15:24
22 lines
2176 bytes
Tom B. wrote in "news.software.readers" ...

> > 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.
> 
> 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 should have added the above won't work if the header folds :)

-- 
Tom B.      * * * Gravity Web Pages  * * *
http://mpgravity.sourceforge.net/ (official site)
http://gravity.tbates.org/
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243251
Author: Tom B.
Date: Tue, 16 Nov 2010 19:49
29 lines
2162 bytes
VanguardLH wrote in "news.software.readers" ...

[trimmed]

> The use of Header in an action rule seems to look for that string to
> appear anywhere in the article, including in the body, and also of
> parsing its value off into the body section.  I'm accustomed to using
> the greedy versions of regex so maybe I need to think how to code the
> regex to be non-greedy so somehow it cannot extend beyond a single line.

[trimmed]

Greediness can be turned off on the repetitions "*" and "+" with a 
question mark. As in "*?" and "+?"

PCRE also has some weirdo option to turn off greediness for the 
whole PCRE. I think it is (?U) but haven't used that one 
personally.

We ran into this stuff with Gravity. We decided to allow matching 
on all headers by just sending the whole article, headers and all 
through the PCRE engine. But the actual matching is easier said 
than done for the average user, because of the greediness, the dot, 
the $, and the multiline matching.

-- 
Tom B.      * * * Gravity Web Pages  * * *
http://mpgravity.sourceforge.net/ (official site)
http://gravity.tbates.org/
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243254
Author: 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.
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243255
Author: Oliver Cromm
Date: Tue, 16 Nov 2010 22:37
40 lines
3232 bytes
* VanguardLH:

[...]

> 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). 

It certainly is implemented. If, in your example, you change the regexp
to the following, you should have no match (at least on the .41 version
of Dialog):

 (?-s)^Path: .+report\.othernsp\.com$

Now change to (?s) or remove the switch, and you get a match, spanning
two lines.

I forgot about (?-s) again, even though that's what I used before to
test on single headers. However, I had no need of testing the end of
line at the same time.

As for (?-m), it is the opposite of what I remembered: With (?-m), ^ and
$ don't match lines any more, only the whole string, so that's what you
don't want. The examples you gave should be OK with (?-s), maybe your
tests were too complex to see it?

-- 
die gugel gehört seit je zur narrenkleidung:
  GRIMM, Deutsches Wörterbuch
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243256
Author: VanguardLH
Date: Tue, 16 Nov 2010 23:34
94 lines
5960 bytes
Oliver Cromm wrote:

> * VanguardLH:
> 
> [...]
> 
>> 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). 
> 
> It certainly is implemented. If, in your example, you change the regexp
> to the following, you should have no match (at least on the .41 version
> of Dialog):
> 
>  (?-s)^Path: .+report\.othernsp\.com$
> 
> Now change to (?s) or remove the switch, and you get a match, spanning
> two lines.
> 
> I forgot about (?-s) again, even though that's what I used before to
> test on single headers. However, I had no need of testing the end of
> line at the same time.
> 
> As for (?-m), it is the opposite of what I remembered: With (?-m), ^ and
> $ don't match lines any more, only the whole string, so that's what you
> don't want. The examples you gave should be OK with (?-s), maybe your
> tests were too complex to see it?

Yep, found out after some more testing that (?s) is the default.  From
what I've read:
 
. (dot)
Matches on any character EXCEPT \r and \n.

Not in Dialog.  I also found out the (?-s) would work but some of my
test cases still ended up including the linebreak.  For example, in
testing the Path header and allowing any host for a particular domain
for a node in the path:

(?-s)^Path: .+![^!]+\.alt\.net$

the [^!]+ was testing for one, or more, of any character OTHER than the
bang (since that is the node delimiter in the Path header).  Alas, it
included the linebreak so I ended up still doing a multi-line parse
despite using the (?-s) modifier.  

One solution was to use the lazy (non-greedy) version as [^!]+? (along
with the (?-s) modifier).  Another was to use [^!\r]+ since that also
excluded the carriage return character from a matching character.
However, since I was testing for the string to be at the end of the
line, I realized it really didn't matter what host was specified for the
injection domain and just changed it to:

(?-s)^Path: .+\.alt\.net$

Actually I used (as a baseline):

(?-s)^Path: .+\.alt\.net(!not-for-mail)$

According to Altopia's FAQ, their users are allowed to pre-load the Path
with their own domain, if they own one (or simply claim or think or
falsify that they one one).  The pre-loading goes before alt.net so this
rule still works.  The problem is Altopia does not enforce this syntax
and I have seen the poster's domain *after* the alt.net injection node
in the Path header; however, each time the poster stuck their domain
after the "not-for-email" string so the following works:

(?-s)^Path: .+\.alt\.net(!not-for-mail.*)?$

The (?-s) keeps the parsing to within the line.  If I get trickier with
the expression, like trying to re-add the [^!]+ to denote that any host
for a domain can be specified, as in [^!]+\.alt\.net then it doesn't
matter that I used (?-s) as the [^!]+ included the linebreak.  So I have
to instead use [^!\r]+ or [^!]+? even though I am also using (?-s).
That is probably because (?-s) is the DOTALL option and affect the dot
specifier but not when I'm using ?, +, or * on other characters.

Good thing Dialog comes with its own regex tester since sometimes it
just is not obvious why matches don't work or are more extensive than
desired.  I've also had to get used to testing on multiple lines of test
text with similar matching strings in the other lines just to be sure
that the parsing doesn't go beyond the one line where I really do want
to test.
Re: Dialog (regex defect): Action rule using "Header" scans into body of post
#243265
Author: Tom B.
Date: Wed, 17 Nov 2010 20:36
37 lines
2879 bytes
VanguardLH wrote in "news.software.readers" ...

[trimmed]

> 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 think the universal "\n" is for *printing* so the C program or 
perl script will print the appropriate line ends depending on the 
OS. But usenet articles always (I think always) use 0D 0A for line 
endings or new lines regardless of the OS.

I have not tried it but "\r" probably works as well as "\r\n" 
because the \r would match first, so the \n may be extraneous.

-- 
Tom B.      * * * Gravity Web Pages  * * *
http://mpgravity.sourceforge.net/ (official site)
http://gravity.tbates.org/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads