精華區beta RegExp 關於我們 聯絡資訊
我的程式要讓使用者輸入類似Excel的Formula ex: 123 + 1000 (value + 2) * 100 我打算先用regex將運算元、運算子拆出來 這是我用網站上的測試工具測試的結果,測試結果是ok的 http://www.badongo.com/pic/5881906?size=original 可是當我套用到C++時就出錯了 底下是我的程式碼,regex_match 傳回值都是false PS. 我用的VS 2008 sp1 的regex std::string infix = "123+1000"; const std::tr1::regex pattern("([0-9a-zA-Z.]+|[+\\-*/])"); std::tr1::smatch result; if (std::tr1::regex_match(infix, result, pattern)) // fail { std::tr1::smatch::const_iterator it = result.begin() + 1; while (it != result.end()) { ParseOp(*it); ++it; } } 請問一下是什麼地方出錯了嗎??? orz -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.46.205.174
Sdany:注意看你的pattern +\\-*/ 多了一個 \ 06/24 12:35