I tried to write a method which acts like Java's Matcher::replaceFirst(String replacement). I know how to replace all matches in a std::string, with std::regex_replace, but how can I only replace the first match of a regex in a string?
You can use std::regex_replace with an additional flag, std::regex_constants::format_first_only, to get the result you want.
Take a look at http://en.cppreference.com/w/cpp/regex/regex_replace for additional information.
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