
capourrait@free.fr wrote:
Hi,
It seem that there is a problem when using the substr function in regex_match(). If you build and run the following code, it works fine. But try to comment the 6th line in findC function and uncomment the 7th line. Under Visual C++ 2005, I get the following: Debug assertion failed! Program: ..........exe File: ..........\vc\include\xstring Line: 271 Expression: string iterators incompatible
Did I miss something?
Yes: substring() returns a *temporary* string object, by the time that regex_match returns the string it has searched has gone out of scope and been destroyed, so all the iterators stored in the match are now invalid. If you want to search a substring then you must assign the string to an object before calling regex_match. But better, use the iterators directly: if ( boost::regex_match(iText.begin()+2, iText.end(), match, regularExp) ) HTH, John.