4.1.2 Pragma regex

Another pragmatic comment, ‘#pragma regex’, controls compilation of expressions. You can use any number of such pragma directives in your ‘mailfromd.mf’. The scope of ‘#pragma regex’ extends to the next occurrence of this directive or to the end of the script file, whichever occurs first.

The syntax of this pragma is:

 
#pragma regex [push|pop] [list-of-flags]

where push and pop are optional sub-commands discussed in detail below, and list-of-flags is a whitespace-separated list of regex flags. Each regex-flag is a word specifying some regex feature. It can be preceded by ‘+’ to enable this feature (this is the default), by ‘-’ to disable it or by ‘=’ to reset regex flags to its value. Valid regex-flags are:

extended

Use POSIX Extended Regular Expression syntax when interpreting regex. If not set, POSIX Basic Regular Expression syntax is used.

icase

Do not differentiate case. Subsequent regex searches will be case insensitive.

newline

Match-any-character operators don't match a newline.

A non-matching list (‘[^...]’) not containing a newline does not match a newline.

Match-beginning-of-line operator (‘^’) matches the empty string immediately after a newline.

Match-end-of-line operator (‘$’) matches the empty string immediately before a newline.

For example, the following pragma enables POSIX extended, case insensitive matching (a good thing to start your ‘mailfromd.mf’ with):

 
#pragma regex +extended +icase

Optional modifiers push and pop can be used to maintain a stack of regex flags. The statement

 
#pragma regex push [flags]

saves current regex flags on stack and then optionally modifies them as requested by flags.

The statement

 
#pragma regex pop [flags]

does the opposite: restores the current regex flags from the top of stack and applies flags to it.

This statement is useful in module and include files to avoid disturbing user regex settings. E.g.:

 
#pragma regex push +extended +icase
 .
 .
 .
#pragma regex pop