2017-03-13 72 views
0

我正在尋找一個特定字符的第一次出現相匹配的解決方案的第一次出現,說「<」的標誌:升壓regex_search - 匹配到一個字符

這是我的代碼:

std::string sRegex("a-color-price'.*\\$(.*?)<"); 
boost::regex regex(sRegex, boost::regex::icase); 
std::string sStr("<span class='a-color-price'>$8.36</span></div> $7.99 per month\" \"cartContent\":{\"html\":\"<div id='nav-cart-flyout' </sdd>"); 
boost::cmatch result; 
if (boost::regex_search(sStr.c_str(), result, regex)) 
{ 
    std::string sResult(result[1].first, result[1].second); 
} 

我希望sResult是 「8.36」,而是它包含這個字符串: 「每月7.99」 「cartContent」:{ 「HTML」: 「」

感謝你的幫助。

回答

1

你正在尋找一個非懶惰方式$(匹配和回溯)使.*一個.*?,並在第一時間找到一個$ occures

點擊here看到它的演示匹配

+0

作品,謝謝! – robert

相關問題