Consider the following program:
#include <iostream>
#include <regex>
int main(int argc, char* argv[]) {
if (argc==4)
std::cout << std::regex_replace(
argv[1], std::regex(argv[2]), argv[3]
) << std::endl;
}
Running
./a.out a_a_a '[^_]+$' b
gives the expected result a_a_b. But running
./a.out a_a_a '[^_]*$' b
prints a_a_bb.
boost::regex_replace has the same behavior.
I don't understand why the empty string after the last a gets matched again, when I've already consumed $.