badstoms
badstoms

Reputation: 217

std::regex_match issue with VS2010

I have trouble with the following code:

std::cmatch what;
std::regex regExp("(\\[-?\\d+\\])+", std::regex_constants::ECMAScript);
std::cout << "std::regex1: " << std::regex_match("[-123]", what, regExp);
std::cout  << "std::regex2: " << std::regex_match("[-123][456]", what, regExp);

boost::cmatch what2;
boost::regex regExp2("(\\[-?\\d+\\])+", boost::regex_constants::ECMAScript);
std::cout << "boost::regex1: " << boost::regex_match("[-123]", what2, regExp2);
std::cout << "boost::regex2: " << boost::regex_match("[-123][456]", what2, regExp2);

I expected that the second expression ("std::regex2") returns true, but it doesn't. The same expression in boost returns true.

I played around a bit and found out, that it matches [123][-456] or [123][456][-789]. The "-" is only accepted for the last element, although it is optional for all. Is this a bug or am I doing something wrong?

Best regards, Markus

P.S.: I use VS2010.

Upvotes: 0

Views: 558

Answers (1)

user2369820
user2369820

Reputation:

I agree with you that the "std::regex2" expression should return true. I too was able to verify this in Visual Studio 2010 and reproduced the same problem.

So I tried the same code in Visual Studio 2012 and this time your code produces the expected answer (true). So the answer is that this is broken in VS2010 and fixed in VS2012.

There were several regex bugs fixed in Visual Studio 2012 so this should explain the differences between VS2010 and VS2012. See the following page for a list of STL bugs fixed in VS2012.

http://blogs.msdn.com/b/vcblog/archive/2012/06/15/10320846.aspx

Upvotes: 1

Related Questions