如何在c ++ regex_replace中隔离backrefernce

时间:2015-10-29 08:54:37

标签: c++ c++11

我使用以下代码:

#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}隔离,但它没有用。

0 个答案:

没有答案