在字符串ss中,我该如何用
"3*("
替换"3 ("
?(需要适用于任意数字。)std::string result;
std::string ss;
static const std::regex nn1 ("\\)(\\d)");
static const std::regex nn2 ("(\\d)(\\s\\()");
ss = "5 + 3 (2 + 1)";
std::regex_replace (std::back_inserter(result), ss.begin(), ss.end(), nn2, "\d*($2");
std::cout << result << "\n";
编译器错误行7 - '\d'
是一个未被识别的转义序列。(我尝试在那里使用'\\d'
.)
MS Visual Studio 2013
(这不是提出的问题的重复,因为这涉及更改字符而不是插入字符,并且这处理不能在替换字符串中使用正则表达式并且必须解决该限制的方法,选择的答案通过先使用$1来解决这个问题。)