I am using the boost regex library in my code. I have a simple application that compiles and runs correctly on a machine that is running Fedora. When I compile the same code on SUSE linux, all but the first submatch string is empty.
The code is as follows
const string pattern = "(abc)(def)";
const string target = "abcdef";
boost::regex regexPattern(pattern, boost::regex::extended);
boost::smatch what;
bool isMatchFound = boost::regex_match(target, what, regexPattern);
if (isMatchFound)
{
for (unsigned int i=0; i < what.size(); i++)
{
cout << "WHAT " << i << " " << what[i] << endl;
}
}
The output on fedora is the following
WHAT 0 abcdef
WHAT 1 abc
WHAT 2 def
The output on SUSE is the following
WHAT 0 abcdef
WHAT 1
WHAT 2
I cannot seem to find any reference to a similar problem anywhere. I assume there is a simple fix, but I havent been able to find it despite days of scouring the web.
The compilers have the following versions.
Fedora : g++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
SUSE : g++ (GCC) 4.1.2 20070115 (SUSE Linux)
I am using Boost version 1.48.0 in both cases. I don’t have root on either machine.
Updating the compiler to a later version fixed the issue. I am suprised compiling boost with the older 4.1 compiler silently broke the submatch functionality on that SUSE box.