procmail
[Top] [All Lists]

Re: Getting partial matches from a string without forking an outside process

2005-01-08 15:45:21
On Sat, Jan 08, 2005 at 09:56:11PM +0100, Ruud H.G. van Tol wrote:

Toen wij Ruud H.G. van Tol kietelden, kwam er dit uit:
Toen wij Robert Allerstorfer kietelden, kwam er dit uit:

deleting 2
characters from the end is nearly impossible without forking an
outside process".

That remark is about strings like "xxxxxx6xxx6xxx6xxxx".

Check out the various uses of rep.inc on how to create regexes that
can do exactly what Jari names 'nearly impossible'.

  var = 'xxxxxx6xxx6xxx6xxxx'

  :0
  *  1^1 var ?? .
  * -2^0
  {
    rep_Repeat = "$="
    rep_String = '.'

    INCLUDERC = 'inc/rep.inc'   # rep_Return becomes 17 dots

    :0
    *$ var ?? ^^\/$rep_Return
    { var_Left = "$MATCH" }

    :0
    * var ?? ()\/..^^
    { var_Right = "$MATCH" }

  }


Not bad.  I think it still doesn't need to be so complicated.
Here is my solution.

Set "$LOP" to however many chars you want to delete.  The string
being lopped is called $FOO here.


First, set your string to $FOO.  Mine will be 25 x's for testing.

 FOO = "xxxxx"  # five chars
 FOO = "$FOO$FOO$FOO$FOO$FOO"  # twenty-five chars (pretend we don't know len)

Now set $LOP.

 LOP = 3  # num of chars to lop off


Here comes the recipe:

#################################################
 :0
 *       1^1 FOO ?? .
 * $ -$LOP^0
 {
    LEN = $= 
    INCLUDERC = lop.rc
 }

#################################################

And here's the lop.rc:

#################################################
 :0
 * $ $LEN^0
 *     -1^0  FOO ?? ^^\/.
 {
    LEN =  $=
    BAR = "$BAR$MATCH"

    SWITCHRC = $_
 }

 FOO = "$BAR$MATCH"

#################################################

-- 
dman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail