###### Replacements

When a pattern is matched, the words that were matched are replaced by the words specified as replacements on the same line of the file.

Controlling character case

Replaced words are subject to character case translation unless they are enclosed in slash characters (/). Each word where you want to specify the character case should individually be enclosed in slashes. For example, to translate H AND R BLOCK to H&R Block, use the following pattern:

H AND R BLOCK : /H&R/ /Block/

Again, note that each word is enclosed in slashes, not the entire replacement.

Copying text from the input

The items in the pattern are numbered automatically, beginning at 1. You can use the matched word in your replacement pattern using \ followed by the number of the item. For example,

READ (A|AN|ONE) (BOOK|MAGAZINE) : READ A \3

A more complex example is

(AT|ON|FROM) ".*"{1,5} DOT (COM|GOV) : \1 \2.\4

This rule would change

learn more about x at my health plan dot gov or by calling

to

learn more about x at myhealthplan.gov or by calling

The first item, (AT|ON|FROM), replaces \1 in the replacement. The second item, “.*”{1,5} will match any sequence of one to five words. All of the words that are matched are concatenated without spaces and used in place of \2 in the replacement. Finally, the last item, (COM|GOV), replaces \4 in the replacement.

Note that the same rule would change

traffic information at nys dot dot gov

to

traffic information at nysdot.gov

because it finds that the first occurrence of dot is not followed by com or gov, so it keeps looking for a match.

Finally, consider this example:

ZIPCODE '(.*)-(.*)' : ZIP \2.1 PLUS \2.2

This rule would change

ZIPCODE 12345-6789

to

ZIP 12345 PLUS 6789

The reference \2.1 indicates the first group from the second word. Similarly, the reference \2.2 is replaced by the second group from the second word.

If you wanted the entire second word followed by .1, simply place a backslash in front of the dot, like this: \2\.1