Regular expressions are often used when we need not only to find a given sequence but also to replace that sequence with another one. For example, we might want to translate U.S. phone numbers into the form “ddd.ddd.dddd,” where the area code and next three digits are separated by a dot.
When we want to find and replace a regular expression in the input sequence, we call
. Like the search functions,
regex_replace, which is described in Table 17.12, takes an input character sequence and a
regex object. We must also pass a string that describes the output we want.
We compose a replacement string by including the characters we want, intermixed with subexpressions ...