Page 63 - Mercury Manual.book
P. 63
Content Control 58
Mercury's Content Control Filtering Language
In this expression, the expression will only succeed if the word "free" appears in uppercase
characters.
Matching anywhere within the text
Mercury's regular expression parser is designed to start at the beginning of the text it is eval-
uating and to stop matching at the end. As a result, if you want to find a regular expression
anywhere within the text you are examining, you need to start and end the expression with an
asterisk operator (*). To illustrate why this is necessary, consider the following three regular
expressions:
Wearing a fedora hat
Wearing a fedora hat*
*Wearing a fedora hat.
The first of these will only match if the target text consists only of the string "Wearing a fe-
dora hat": if there is text before or after the string, the match will fail. The second will match
only if the text starts with the string "Wearing a fedora hat". If there is any text before the
string, the match will fail, but the "*" at the end ensures that any text following the string will
not prevent a match. The last example will match only if the text ends with "Wearing a fedora
hat" - again, the "*" at the start of the expression will match anything prior to the string.
If you want to find the expression anywhere it occurs in the target text, you need to enter it as
*wearing a fedora hat*
If you forget to add the leading and trailing * operators, the rule will typically not work, and
this error can be quite difficult to spot when you're simply reading the source file.