0

Possible Duplicate:
Is gcc4.7 buggy about regular expressions?

I compile the code below with "g++ test.cpp -std=gnu++0x" . Compilation is successful but when I run./a.out it gives error like that I do not understand why it happens. My operating system s Mint.

Error: " terminate called after throwing an instance of 'std::regex_error' what(): regex_error Aborted (core dumped) "

Code:
// regex_match example
#include <iostream>
#include <string>
#include <regex>

using namespace std;

int main ()
{
  string s ("this subject has a submarine as a subsequence");
  regex e("sub[a-z]");   // matches words beginning by "sub"
  smatch m;

  return 0;
}
Community
  • 1
  • 1
mustafa.yavuz
  • 1,274
  • 2
  • 21
  • 40
  • 3
    gcc doesn't ship with a working regex implementation. You should use Boost.Regex instead. – Praetorian Dec 12 '12 at 22:39
  • Whoever is voting to reopen, this will just get closed again as one of half a dozen duplicates anyway. – ildjarn Dec 12 '12 at 22:51
  • @ildjarn: That's fine, but if there are half a dozen duplicates, it's not too localized, is it? – Benjamin Lindley Dec 12 '12 at 23:04
  • 1
    @BenjaminLindley I feel like if interpreting this question narrowly makes it "too localized" and if interpreting it broadly creates a half dozen "exact duplicates," the compromise should not be to leave open. – djechlin Dec 12 '12 at 23:06
  • The best duplicate is [Is gcc4.7 buggy about regular expressions](http://stackoverflow.com/questions/12530406/is-gcc4-7-buggy-about-regular-expressions), as it gives some more background info. – Jesse Good Dec 12 '12 at 23:07
  • 1
    @djechlin: I agree. The correct action is to list the duplicate(s) prominently, which would have happened automatically if the question was closed as a duplicate. My vote to reopen was in protest to the question being closed as too localized. I was not aware of the duplicates at the time (because they were not displayed prominently). – Benjamin Lindley Dec 12 '12 at 23:20

1 Answers1

7

The code looks fine. GCC's implementation of regex is unusable. Don't waste your time with it.

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