An OmniMark pattern includes string expressions. While static strings are the most common form of string expressions used in patterns, any form of string expression is allowed. This means you can dynamically define a pattern using an operator or function to supply a string expression in a pattern. The following code dynamically defines a pattern using the date operator:
This code does the same thing using a function:
You can pass variables to a function used to dynamically define a pattern, including pattern variables from earlier in the pattern. The following code uses a function to match a pattern in which a digit is followed by the spelled-out version of the number:
define string function spelled-out (value string the-digit) as do scan the-digit match "1" return "one" match "2" return "two" match "3" return "three" done return "" process submit "Please submit 3 (three) copies" find digit => the-digit blank "(" spelled-out(the-digit) ")"
Note that this function returns an empty string if the digit passed does not match any of the cases it deals with. This empty string becomes part of the pattern, which means that the rule given would match the string "Please submit 5 () copies" though not the string "Please submit 5 (five) copies". Every stream function must return a value, so make sure you correctly anticipate the impact of all possible return values on your pattern matching.