Struct RegexReplacer

Struct Documentation

struct RegexReplacer

Public Types

using value_type = char

Public Functions

void regex_replace(std::string &str) const

Replaces all matches of the regex this replacer was constructed from in “str” with “rewrite” it was constructed with. Within “rewrite”, dollar-escaped digits ($1 to $9) can be used to insert text matching corresponding parenthesized group from the pattern. $0 in “rewrite” refers to the entire matching

Example:
Regex const r{"[0-9]+"};
RegexReplacer const repl = r.make_replacer("$0th");

std::string s = "Hello 13 World";
repl.regex_replace(s);

assert(s == "Hello 13th World);

Parameters:

str – the string to replace all matches with, assumed to be valid UTF-8