Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2007-01-27 05:05:23


Richard Hadsell wrote:
> I am having a problem with a regex_match in Boost 1.33.0. Perhaps I
> am missing something; perhaps it is a bug that has been fixed.
>
> The pattern "[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([Ee][+-]?\\d+)?" should
> match only floating-point numbers that can be read by sscanf. (Extra
> escape characters are for C++, of course.) Yet regex_match returns
> true for "3.6.5".
>
> I guessed that the problem might be in the '(...)?' expression just
> before the alternative operator '|', so I tried this:
> "[+-]?(\\d+|\\d+\\.\\d*|\\.\\d+)([Ee][+-]?\\d+)?". With this pattern
> regex_match returns false for "3.6.5". I am using it, but I consider
> it a workaround.
>
> Can someone explain what I have missed or whether this is a bug?

I can't reproduce this with 1.33.1 (there were some regex bugs fixed in the
.1 release), my test case is:

int main(int argc, char* argv[])
{
  try
  {
    boost::regex e("[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([Ee][+-]?\\d+)?");
    std::string text = "3.6.5";
    if(boost::regex_match(text, e))
    {
      std::cout << "Matched!!!" << std::endl;
    }
  }
  catch (const std::exception& e)
  {
    std::cout << e.what() << std::endl;
  }
  return 0;
}

Can you please try again with 1.33.1?

Thanks, John.


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