procmail
[Top] [All Lists]

Re: Eliminating Linefeed embedded in a $MATCH result

1999-04-29 05:10:10
On Thu, 29 Apr 1999 12:45:45 +0200 (MET DST), Ralph SOBEK
<sobek(_at_)irit(_dot_)fr> wrote:
     * B ?? ()\/\<Foobars?\>
If "Foobar" is at the end of the line, $MATCH contains a linefeed.

Wherever "Foobar" is, it will contain +something+ that matched \>
(which as you'll recall is a shorthand for newline plus a negated
character class, unlike in "real" egreps). So whatever you get in
MATCH, you might be expected to somehow pluck off the last character.
This might or might not be easy.

If you do want "something \> matched, except when it's a newline" in
MATCH, trim down MATCH using the character class from procmailrc(5):

    :0
    * ! MATCH ?? ^^\/\<Foobars?[^a-zA-Z0-9_]
    {
        # If you reach here, you know \> must have matched a newline
        #  -- get rid of it
        :0
        * MATCH ?? ^^\/\<Foobars?
        { }
    }

Of course, in the general case when you have something in MATCH and
you want to trim it down to just the alphabetics (as in a substring
where you want to trim off leading and trailing \< \> ... but I take
it that's not what you want here) you can do something like

    * MATCH ?? ^^\<\/[A-Za-z]+

Otherwise, the trimming example for above (where you match on the same
regex minus the last character(s)) can be generalized to some extent.
One would wish there was a way to limit MATCH context-sensitively in a
more general manner, though.

Hope this helps,

/* era */

Philip: It would probably break some old badly written recipes, but
how about take a second \/ to mean, stop MATCHing here. So

    # If you haven't been paying attention: this is currently a syntax error
    * B ?? ()\<\/Foobars?\/\>

would be a way to grab "Foobar" or "Foobars" (only) into MATCH, but
only when the trailing context matches \>. (I bet this has been
suggested before.)

-- 
.obBotBait: It shouldn't even matter whether     <http://www.iki.fi/era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>
 * Sign the European spam petition! <http://www.politik-digital.de/spam/en/> *