C ++ 11 std :: regex_match returning an extra character

Possible duplicate:
Is gcc4.7 a bug in regular expressions?

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

Below is my conclusion:

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] 

So far, the output sample:

 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] 

Please note that the wrong one was extracted on my [bject] machine. Any ideas?

+4
source share
2 answers

According to gcc, the implementation status (version 4.6.3) of the regex library is not yet fully implemented. It does not cause errors and does not give any warnings. Which is really unpleasant.

However, others have observed this earlier and with later versions:

A general suggestion is to continue to use Boost.Regex or to try another compiler.

See this answer for further reading.

+3
source

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 seems like a bug in the GNU implementation.

0
source

Source: https://habr.com/ru/post/1439994/


All Articles