在字符串SS,我怎麼更換"3 ("
與"3*("
(它需要在一般工作的任何數字)C++的正則表達式:?替換 d S(用 d *(
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解決。)
我有一個大致的要求:當你獲得幫助,請還清與upvotes和接受的答案。 –
[C++ regex \ _replace不做預期替換]的可能重複(http:// stackoverflow。com/questions/29991889/c-regex-replace-not-doing-intended-substitution) – AndyG
我鏈接的dup是另一個基本相同的問題,Mike。 – AndyG