I'm writing a program that does string manipulations with boost::regex
.
In all the cases I need the functionality of regex_search
, but only specific cases need regex_replace
.
Is there a way to combine the two so that replacing doesn't redo the work of searching?
I know that after calling
boost::regex re;
std::string str, fmt;
// . . .
boost::smatch match;
regex_search( str, match, re );
match
contains information about matching, but
match.format( fmt );
doesn't do what
regex_replace( str, re, fmt );
does.
Perhaps use a dynamic replacement: C++ boost regex replace with conditions