1

Possible Duplicate:
C++0x regex in GCC

I was trying to transform a file under c++ using regex, some regex_error keeps on occuring, here is the code:

std::ifstream inf(in);
std::ofstream outf(out);
try{
std::regex line_regex("[[:alnum:]]");
std::string line;
while(std::getline(inf,line))
{
    if(std::regex_match(line,line_regex))
        outf<<line<<std::endl;
}

the error message is:

terminate called after throwing an instance of 'std::regex_error'
what():  regex_error

by the way, I'm using gcc 4.7.2 on linux x64.

Community
  • 1
  • 1
flyingfoxlee
  • 1,764
  • 1
  • 19
  • 29
  • 2
    gcc version 4.6.1 had only partial support for std::regex, I don't know if it has been fixed in version 4.7.0 yet, on second thought I think they haven't fixed it check for regex in here http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011 – chipmunk Dec 16 '12 at 07:13
  • I tried `std::regex` on 4.6.2 and couldn't get it to work either. Ended up wrapping PCRE instead. I think the Perl regex syntax is the best and most expressive and PCRE is an extremely stable time-honored library. – Andrew Tomazos Dec 16 '12 at 08:42

1 Answers1

5

GCC's implementation of <regex> is unusable. Don't waste your time on it.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165