0

I'm looking for a solution that matches the first occurrence of a specific character, say a "<" sign:

This is my code:

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);
}

I expect sResult to be "8.36" and instead it contains this string: "7.99 per month" "cartContent":{"html":""

Appreciate your help.

robert
  • 1
  • 1

1 Answers1

1

you are looking for a $ in a non lazy way (match and backtrace) make the .* a .*? and it matches the first time it finds a $ occures

click here to see a demo of it

l3lackwolf
  • 96
  • 4