On Wed, Jun 29, 2005 at 10:38:47AM -0500, Mr Duck wrote:
[ Jake Di Toro <karrde+procmail(_at_)viluppo(_dot_)net> wrote: [1] ]
Ancoring is simply tying something to the begining/end of a line
to ensure that the match happened there and not at some random
point in the middle of a string.
So, what's the difference between two carets (^^) and one (^)?
Yes, as Jake says, anchoring is akin to what a ship's anchor
does: keeps the ship from drifting unexpectedly. Think of
a dog on a leash. The leash is the regex. If you let go
of the least, the dog, with regex, can run anywhere at all.
The leash does no good. If you hold on to the leash, the dog's
ambit is curtailed, kept where you want it to be.
If we look for a To: header and we don't anchor it to the
left edge of the header space, procmail will look through all
text in the header for the string "To:". It may find it
where we weren't expecting it, such as in a header called
"X-Original-To:". Even if it doesn't find the wrong thing,
it's quite a lot of work for procmail to skitter rightward
through all header lines to see if there is a To: header.
"^^" is described, albeit in brief, in the procmailrc man
page. Actually, both the tokens you are asking about are
described next to each other in the same place:
The following token meanings are special procmail extensions:
^ or $ Match a newline (for multiline matches).
^^ Anchor the expression at the very start of the search area,
or if encountered at the end of the expression, anchor it at
the very end of the search area.
So if we use this recipe:
:0
* B ?? ^\/Now is the^time for all^good men to come^to our aid
{ AID = $MATCH }
and we succeed at capturing AID, we will have a multi-line match:
6:18pm [~/Mail] 837[0]> tail $SPAMPLE
X-Recipe-ID: UBE.TRUST<LOWEST, UBE.DT.!FR_.DATE_SPOTTY:PASTHOUR, UBE.RC.DODGEY
Now is the
time for all
good men to come
to our aid and save our souls.
Yr. obdnt. srvnt.,
John Q. Public
6:19pm [~/Mail] 839[1]> procmail -m DEFAULT=/dev/null VERBOSE=y test.rc <
$SPAMPLE
procmail: [843] Wed Jun 29 18:19:46 2005
procmail: Assigning "MAILDIR=."
procmail: Rcfile: "test.rc"
procmail: Assigning "MATCH="
procmail: Matched "Now is the
time for all
good men to come
to our aid"
procmail: Match on "^\/Now is the^time for all^good men to come^to our aid"
procmail: Assigning "AID=Now is the
time for all
good men to come
to our aid"
procmail: Assigning "LASTFOLDER=/dev/null"
procmail: Opening "/dev/null"
From vdwyxfemaqjru(_at_)willeke(_dot_)com Fri Jun 24 23:04:00 2005
Subject: [Auto-Reply] Tip Sheet boosts your portfolio
Folder: /dev/null
Look at the part I marked in the margin.
So now we could say
:0
* AID ?? ^\/good men
{ GOOD = $MATCH }
and we'd match "good men", starting at the left edge.
But we're not at the start of the search expression, because
that is up two lines at "Now is the". If we want to anchor
on the start of the expression, we could do this:
:0
* AID ?? ^^.*\<\/is
{ IS = $MATCH }
We'll only match "is" if it's on the first line of the
multilne expression.
- dman
[1] I added the attribution back in. Please don't forget
to attribute quoted text!
____________________________________________________________
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