procmail
[Top] [All Lists]

Re: extracting all but three characters

1996-08-24 22:19:01
Is there a way extract all but the last three characters of a string (with
the MATCH facility, that is; I know how to do it by forking cut or sed or
expr or ksh) into $MATCH if any character can occur at any position?

For example, if we know that the last character to extract is a digit and
the remaining three are not digits, this works:

   :0 # extract though last digit
   * BIGSTRING ?? ^^\/.*[0-9]
   { SAVEDPIECE="$MATCH" }

But what if we don't have any such particulars to rely on?

At this point, you must either use a minimally matching pattern, or
use a subsequent "sed" regexp extraction to reduce the unwanted
part of MATCH.

This is a general problem in matching algorithms.  Long ago, I wrote
such an algorithm and implemented what I called "fence" and
"lookahead":  being the boundaries of left-hand and right-hand contexts
outside of the "match".

Perl 5 has recently added to its excellent regexp matching primitives
two similar ideas: positive and negative look-ahead assertions (?=PAT) 
and (?!PAT).

It might be possible to persuede Stephen to add something similar, but
then he would have to document the procmail regexp, instead of relying
on egrep :^).

Since "\/" marks the beginning of MATCH, why not make the second
occurance of "\/" mark the end of MATCH?  I'll be that it is not too
difficult to add.

_____________________________________________________________________
Alan Stebbens <stebbens(_at_)sgi(_dot_)com>      http://reality.sgi.com/stebbens

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