Matching Any Token Not in a Class: $~

The prefix is used to match any single token in the workspace that is not in a class. It is used fewer than a dozen times in a typical production configuration file, but when the need for its properties arises, it can be very useful.

To illustrate, consider a network with three PC machines on it. The PC machines cannot receive mail, whereas all the other machines on the network can. If the list of PC hostnames is defined in the class {PChosts}:

C{PChosts} pc1 pc2 pc3

a rule can be designed that will match any but a PC hostname:

R $* < @ $˜{PChosts} >     $@ $1 < @ $2 >       filter out the PC hosts

Here the LHS looks for an address of the form:

"user" "<" "@" "not-a-PC" "">

This matches only if the @ token is not followed by one of the PC hosts listed in class $={PChosts}. If the part of the workspace that is tested against the list provided by is found in that list, the match fails.

Note that the $digit positional operator in the RHS (the $2 in the preceding example) references the part that matches $˜{PChosts}. That is, $2 references the token in the workspace that is not in the class {PChosts}. If the workspace contains ben<@philly>, the $2 references the philly.

Also note that multitoken expressions in the workspace will not match. That is, for multitoken expressions in the workspace, is not the opposite of $=. To illustrate, consider this mini configuration file:

V10 CX hostA.com Stest R $˜X $@ no $1 is not in X R $=X $@ yes $1 is in X R $* $@ neither ...

Get sendmail, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.