0

Trying to create a std::regex object with a []-enclosed character class in C++ I am getting an error:

std::regex re0("\\.");
std::regex re1("a");
std::regex re2("a+");
std::regex re3("a*");
std::regex re4("[az]");  // fails
std::regex re5("[a-z]");  // fails

This results in the following error:

unknown file: Failure
C++ exception with description "regex_error"

I am using gcc version 4.8.2.

The syntax seems correct according to the reference and works in other regex compilers (I tried Python's re and regex101.com). How can I create a regular expression object for a range character class in C++?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
jotrocken
  • 2,263
  • 3
  • 27
  • 38
  • 5
    gcc 4.8.x is known to be buggy and incomplete regarding `std::regex` implementation. Use gcc 4.9.x instead please. – πάντα ῥεῖ Mar 06 '15 at 18:58
  • 1
    Although the duplicate question I've linked to asks about gcc4.7, the same applies to gcc4.8 – Praetorian Mar 06 '15 at 19:05
  • @Praetorian good to know! Unfortunately, that article didn't show up in the SO search. I didn't expect the implementation of to be incomplete in the first place, rather than suspected a wrong usage on my part. – jotrocken Mar 07 '15 at 12:03

0 Answers0