C++ regular expression program

closed account (ypfz3TCk)
I compiled this program using g++4.7 -std=c++11. It compiles but won't run. Can you give me help to get this working?

#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:
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
Abort trap (core dumped)

I think GCC 4.7 doesn't have full <regex> support.
Last edited on
closed account (ypfz3TCk)
ok thanks
Works with clang++ (prints "freind"), but to use regex with gcc, you're going to need boost.
Topic archived. No new replies allowed.