|
Boost Users : |
Subject: Re: [Boost-users] boost::regex - I do not understand why this test fails.
From: Mauricio Gomes (mgpensar_at_[hidden])
Date: 2010-06-23 13:54:59
>
> It would probably work better if you used \\s+ consistently for internal
> spaces.
>
> In Christ,
> Steven Watanabe
>
Thank you Steven, the test below works fine now.
Best regards,
Mau.
BOOST_AUTO_TEST_CASE(example_test)
{
boost::cmatch res;
std::string s = " JETIX 2,957,081 643,225.51 0.00";
static const std::string& REGEX1 =
"\\s*(\\w+){1}\\s+([\\d,\\.]+){1}\\s+([\\d,\\.]+){1}\\s+([\\d,\\.]+)\\s*$";
static const std::string& REGEX2 =
"\\s*(\\w+){1}\\s+(\\w+){1}\\s+(\\w+){1}\\s+([\\d,\\.]+){1}\\s+([\\d,\\.]+){1}\\s+([\\d,\\.]+){1}\\s*$";
boost::regex rx(REGEX1);
if (boost::regex_match (s.c_str(), res, rx))
{
BOOST_CHECK_EQUAL ("JETIX" , res[1]);
BOOST_CHECK_EQUAL ("2,957,081" , res[2]);
BOOST_CHECK_EQUAL ("643,225.51", res[3]);
BOOST_CHECK_EQUAL ("0.00" , res[4]);
}
else
{
BOOST_FAIL ("It was supposed to match.");
}
boost::cmatch res2;
boost::regex rx2(REGEX2);
bool match = boost::regex_match (s.c_str(), res2, rx2);
for (unsigned i = 0; i < res2.size (); ++i)
std::cout << res2[i] << std::endl;
if (match)
BOOST_FAIL ("It was NOT supposed to match.");
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net