17.3.4. Using regex_replace
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 regex_replace
. 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 ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.