Next: Boolean expressions, Previous: Relational expressions, Up: Expressions [Contents][Index]

In addition to the traditional relational operators, described
above, `mailfromd`

provides two operators for regular
expression matching:

Expression | Result |
---|---|

x `matches` y | True if the string x matches the
regexp denoted by y. |

x `fnmatches` y | True if the string x matches the
globbing pattern denoted by y. |

The type of the regular expression used by `matches`

operator
is controlled by `#pragma regex`

(see pragma regex). For example:

$f ⇒ "gray@gnu.org.ua" $f matches '.*@gnu\.org\.ua' ⇒`true`

$f matches '.*@GNU\.ORG\.UA' ⇒`false`

#pragma regex +icase $f matches '.*@GNU\.ORG\.UA' ⇒`true`

The `fnmatches`

operator compares its left-hand operand with a
globbing pattern (see glob(7)) given as its right-hand side
operand. For example:

$f ⇒ "gray@gnu.org.ua" $f fnmatches "*ua" ⇒`true`

$f fnmatches "*org" ⇒`false`

$f fnmatches "*org*" ⇒`true`

Both operators have a special form, for *‘ MX’ pattern matching*.
The expression:

xmx matchesy

is evaluated as follows: first, the expression `x` is analyzed and, if
it is an email address, its domain part is selected. If it is not,
its value is used verbatim. Then the list of ‘`MX`’s for this domain is
looked up. Each of ‘`MX`’ names is then compared with the regular
expression `y`. If any of the names matches, the expression
returns true. Otherwise, its result is false.

Similarly, the expression:

xmx fnmatchesy

returns true only if any of the ‘`MX`’s for (domain or email) `x`
match the globbing pattern `y`.

Both `mx matches`

and `mx fnmatches`

can signal the
following exceptions: `e_temp_failure`

, `e_failure`

.

The value of any parenthesized subexpression occurring within the
right-hand side argument to `matches`

or `mx matches`

can be
referenced using the notation ‘`\ d`’, where

if $f matches '.*@\(.*\)\.gnu\.org\.ua' set message "Your host name is \1;" fi

Remember that the grouping symbols are ‘`\(`’ and ‘`\)`’ for
basic regular expressions, and ‘`(`’ and ‘`)`’ for extended
regular expressions. Also make sure you properly escape all special
characters (backslashes in particular) in double-quoted strings, or
use single-quoted strings to avoid having to do so
(see singe-vs-double, for a comparison of the two forms).

Next: Boolean expressions, Previous: Relational expressions, Up: Expressions [Contents][Index]