0

I've ran into some pretty weird behavior using c++11 std::regex-es. It repeatedly thrown std::regex_error exceptions, with even the most basic tweaks in the contents of a capturing group, so I wrote up some test cases and checked each one, below are the results.

            #include <regex>

            std::regex reg;

1  error    reg.assign("[0-9]");
2           reg.assign("[0-9]", std::regex_constants::extended);
3           reg.assign("[0-9]*", std::regex_constants::extended);
4  error    reg.assign("([0-9])", std::regex_constants::extended);
5  error    reg.assign("([0-9]*)", std::regex_constants::extended);
6  error    reg.assign("a([0-9])", std::regex_constants::extended);
7  error    reg.assign("a([0-9]*)", std::regex_constants::extended);
8           reg.assign("[0-9]+([0-9]*)", std::regex_constants::extended);
9           reg.assign("[a-z]+([0-9]*)", std::regex_constants::extended);
10          reg.assign("a(.*)");
11          reg.assign("a(.*)", std::regex_constants::extended);

I understand ECMAScript grammar(default) doesn't support the [0-9] syntax, but the extended grammar does, so my question is:

Why don't 4, 5, 6 and 7 work, if 8 and 9 do?

update #1:

the default grammar, ECMAScript does support it (thanks Neil Butterworth), I only got that idea from the tests I tried.

Tapir
  • 25
  • 4

1 Answers1

-1

"Regex support in libstdc++ was extremely broken until not so long ago, the version shipped with Ubuntu 14.04 probably was still a bad one." – Matteo Italia

"gcc 4.8? known to be buggy as hell. Move to v6 or 7 immediately!" - Richard Hodges

Thank you!

Tapir
  • 25
  • 4