C++ regular expression problem

I compiled this program after reading the code from C++ Primer 5th Edition page 729. I used the C++11 standard flag on the gcc 4.7 compiler. The program compiles without any problems:
Code:
#include <iostream>
#include <regex>
#include <string>

int main()
{
  std::string pattern("[^c]ei");
  pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
  
  std::regex r(pattern);
  std::smatch results;

  std::string test_str = "receipt freind theif receive";

  if(std::regex_search(test_str, results, r))
    std::cout << results.str() << std::endl;

  return 0;
}

When I run the program I get:
Code:
terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Abort trap (core dumped)

I have tried this program with exception handling to try and find out more about the error, but all I got was error signal 4. I know that the regex class uses ECMAscript as default and that this is tested at runtime. Unfortunately, I cannot see what the problem is.
 
ECMA-262 does not support the class format of '[[:alpha:]]' and uses '\w' for that. If you want to use POSIX.2 regex format you have to define your class as 'basic' or 'extended'.
 
Back
Top