procmail
[Top] [All Lists]

Re: Eliminating Linefeed embedded in a $MATCH result

1999-05-02 18:06:34
First, my apologies for some horribly incorrect answers in this thread. My
first answer worked only in the very limited case for which it was
originally developed and the followup, which I claimed was untested, was
worse. I believe I have tested enough cases now to understand what is
happening.

David is, of course, correct in what is quoted here:
If Ralph wants multiline matches but not the final newline on the last line
of the matched text, nor any closing empty lines but just up through the
last non-newline character from the first match,

  * MATCH ?? ^^\/(.*$)*.+

Furthermore, the best way I have found to also eliminate trailing
whitespace on the last line of the MATCH is to simply repeat David's
formulation with a similar one, this time ending on the last non-whitespace
character. This can be extended to trimming any known character from a
string, a technique which has been discussed in the past.

 :0 flags as needed
 * some condition which places text into MATCH
 * MATCH ?? ^^\/(.*$)*.+
 * MATCH ?? ^^\/(.*$)*.*[^      ]
 { Result=$MATCH }

One caveat. When the original match contains a leading empty line (newline
only), that empty line is removed from the result. Intermediate
newline-only lines and trailing whitespace are preserved. Thus, if MATCH
contains:

"
ABC
"

procmail will give 

"ABC"

after David's RE is matched. If the MATCH originally held:

"

ABC
"

the result will be

"
ABC"

with only the first newline removed. This is true with 3.11pre4 and
3.11pre7. I have not yet tried other versions. Explanations of this are
welcomed, as are single-RE conditions to remove both trailing newlines and
whitespace.

-- 
Rik Kabel          Old enough to be an adult              
rik(_at_)netcom(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>