Subject: Yanking first word from Subject

From: Andy Rowan <[email-masked]>
Date: Fri, 24 Mar 1995 11:57:30 -0500

A short time ago, David Tamkin wrote

 >| Is there no way to extract a single word from the Subject:
 >| field and then to redefine Subject: as the remainder?

{snip}

 > :0
 > * ^Subject: *magicword\>.*\/[^ ].*
 > | formail -I"Subject: $MATCH" | flist whatever_other_args

I guess I need a little help with this one ... it works, but I'd
like to know how.  That regexp for subject ... matches "Subject:"
at the start of a line, one or more spaces after it, then the
magicword.  Then (have I got this part right?) the character after
the magicword matches with the \>.

Then what does the ".*" BEFORE the \/ represent?  What we're after is
to get everything but the first word (magicword) into $MATCH.

In other words, what does the above regexp do that 
  * ^Subject: *magicword\>\/.*
doesn't do?

==================================================
| Andy Rowan                                     |
| Center for Remote Sensing and Spatial Analysis |
| Rutgers University, New Brunswick NJ USA       |
| [email-masked]                        |
==================================================

---

From: [email-masked] (David W. Tamkin)
Date: Fri, 24 Mar 1995 13:56:45 -0600 (CST)

Andy Rowan actually read my submission and responded,

| A short time ago, [I posted a recipe that included this extraction
| condition:]

|  > * ^Subject: *magicword\>.*\/[^ ].*

| ...  what does the above regexp do that 
|   * ^Subject: *magicword\>\/.*
| doesn't do?

The rule for procmail's MATCH facility is that the left side matches the
shortest possibility and the right side matches the longest possibility.
Now that's different from, say, substitutions in sed or vi, where subex-	
pressions are assigned (if there is any ambiguity) by matching the longest
possibility to the leftmost wildcard.

means this: the left side should contain Subject:, any space before the
keyword, the non-word character that terminates the keyword (you don't
want a match if the keyword is STEP but you receive a letter whose subject
is "Stephanie's baby shower" for example), and the SHORTEST possible match
(even nothing) up to a non-space character.  That's in case someone puts
a colon or a comma after the keyword and then a space.  As soon as procmail
finds a non-space there, that and the rest of the line make up the right
side.  It also makes sure that the right side contains at least one character
that isn't a space.

means this: the left side goes up through the non-word character that
terminates the keyword, and the right side contains the rest of the line.
If there are additional spaces after the end of the left side, they become
part of the right side.  If there is NOTHING after the left side ends, we
have an empty right side.  If there are only spaces after the left side ends,
the right side will consist of a string of spaces.

The way I read the original question -- the person who posted it spoke of
extracting the rest of the words in the subject -- I thought that both of
those possibilities were to be disallowed.  It turned out that the poster
did want to permit those, but I didn't know that when I posted my reply.

Perhaps, given the information the original poster sent me later, I should
have suggested this condition:

* ^Subject: *magicword\/\>.*

If there is nothing for \> to match except the trailing newline, I believe
that $MATCH would be null; is that right, Stephen?  I know that I've had
extraction conditions that ended in $ and $MATCH has never included the
trailing newline in those situations.

David W. Tamkin  Box 3284  Skokie, Illinois  60076-6284
[email-masked]    MCI Mail: 426-1818   +1 312 714 5610