std::regex_replace (Added in C++ 11) replaces all the occurrences. How can I make it replace only the first occurrence?
If the flags parameter to std::regex_replace contains std::regex_constants::format_first_only, only the first match is replaced.
std::regex_replace("12 34",
std::regex(R"(\d+)"),
"num",
std::regex_constants::format_first_only);
stribizhev kindly provided a working example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With