Replace
std::regex_replace
replaces sequences in a text matching a text pattern. It returns in the simple form std::regex_replace(text, regex, replString)
its result as string. The function replaces an occurrence of regex
in text
with replString
.
std::replace
// replace.cpp
...
#include
<regex>
...
using
namespace
std
;
string
future
{
"Future"
};
string
unofficialName
{
"The unofficial name of the new C++ standard is C++0x."
};
regex
rgxCpp
{
R
"
(
C\+\+0x
)
"
};
string
newCppName
{
"C++11"
};
string
newName
{
regex_replace
(
unofficialName
,
rgxCpp
,
newCppName
)};
regex
rgxOff
{
"unofficial"
};
string
makeOfficial
{
"official"
};
string
officialName
{
regex_replace
(
newName
,
rgxOff
,
makeOfficial
)};
cout
<<
officialName
<<
endl
;
// The official name of the new C++ standard is C++11.
In addition to the simple version, C++ has a version of std::regex_replace
working on ranges. It enables you to push...