我使用以下代码:
#include <iostream>
#include <string>
#include <regex>
#include <iterator>
int main ()
{
std::string s ("there is a subsequence in the string\n");
std::regex e ("\\b(a )(subsequence)([^ ]*)");
// with flags:
std::cout << std::regex_replace (s,e,"$11digit$3",std::regex_constants::format_default);
std::cout << std::endl;
return 0;
}
其中$1
和$2
是后引用。上述命令的输出:
there is digit in the string
但输出应该是:
there is a 1digit in the string
很明显,11美元将其作为第11个反向引用,但我只想在反向引用1
的末尾添加$1
。如何对$1
进行isoloate,以便我可以在其后面加一个数字。
我试图将其与${1}
隔离,但它没有用。