[問題] 評估運算式的regex

看板RegExp (正規表示式 Regular Expression)作者 (高橋旺)時間16年前 (2009/05/05 15:30), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
我的程式要讓使用者輸入類似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

06/24 12:35, , 1F
注意看你的pattern +\\-*/ 多了一個 \
06/24 12:35, 1F
文章代碼(AID): #19_-iBIU (RegExp)
文章代碼(AID): #19_-iBIU (RegExp)