4

Possible Duplicate:
Is gcc4.7 buggy about regular expressions?

I followed the example on http://www.cplusplus.com/reference/std/regex/regex_match/ and compiled on Ubuntu 12.04 64-bit with g++ version 4.6.3

The following is my output:

string literal matched
string object matched
range matched
string literal with 3 matches
string object with 3 matches
range with 3 matches
the matches were: [subject] [sub] [bject] 

While the sample output is:

string literal matched
string object matched
range matched
string literal with 3 matches
string object with 3 matches
range with 3 matches
the matches were: [subject] [sub] [ject]

Notice that on my machine [bject] is extracted which is not right. Any ideas?

Community
  • 1
  • 1
Jeremy
  • 4,797
  • 1
  • 18
  • 26

2 Answers2

3

According to the gcc implementation status (ver 4.6.3) the regex library is not yet completely implemented. It throws no errors and provides no warnings. Which is unpleasant, indeed.

However, others have observed this before, with more recent versions as well:

The common suggestion is to further use Boost.Regex or to give a try to another compiler.

See this answer for some further reading.

Community
  • 1
  • 1
moooeeeep
  • 31,622
  • 22
  • 98
  • 187
0

You can reduce the example to:

std::string s("subject");
std::regex e("(sub)(.*)");
std::smatch sm;
std::regex_match(s, sm, e);

even more interesting:

std::string s("subject");
std::regex e("(sub)(ject)");
std::smatch sm;
std::regex_match(s, sm, e);

So, this looks like a bug in the GNU implementation.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198