
Hi!
Weird, but looks more like a VC bug than a regex one - after all the *only* difference between the two examples is whether the string passed to regex_format is a variable or a temporary, so unless I'm missing something it's got to be a compiler problem?
Well, I don't think, it's a compiler problem. stringbuf::str() retuns a temporary string. This is passed on to regex_match(). The real problem is, the data in matchInfo is not stored as a copy of the processed string, but as a reference to its characters. So, when the temoprary string is being destroyed, the result in matchInfo is also lost. Even the following short code failes, using a temporary string as argument for regex_match(): #include <string> #include <iostream> using namespace std; #include <boost/regex.hpp> using namespace boost; main() { reg_expression<char> exp(".*"); cmatch match1; string str = "123456"; if (regex_match(str, match1, exp)) cout << "matchInfo=" << match1.str() << "\n"; cout << "match1.size()=" << match1.str().size() << "\n\n"; cmatch match2; regex_match(string("123456"), match2, exp); cout << "match2=" << match2.str() << "\n"; cout << "match2.size()=" << match2.str().size() << "\n\n"; assert(match1.str()==match2.str()); return 0; } For me, it outputs: matchInfo=123456 match1.size()=6 match2=8Hç 56 match2.size()=6 Martin