regular expression code in Code Blocks

Hi, I'm having trouble when I'm trying to run regular expression code. It compiled fine but when I run it in CodeBlocks I'm getting this error

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


Here is the code (taken from http://www.cplusplus.com/reference/)
As you can see it work fine on cpp.sh. And yes I did enable C++11 support. Anyone know what the problem might be?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string s ("this subject has a submarine as a subsequence");
  std::smatch m;
  std::regex e ("\\b(sub)([^ ]*)");   // matches words beginning by "sub"

  std::cout << "Target sequence: " << s << std::endl;
  std::cout << "Regular expression: /\\b(sub)([^ ]*)/" << std::endl;
  std::cout << "The following matches and submatches were found:" << std::endl;

  while (std::regex_search (s,m,e)) {
    for (auto x:m) std::cout << x << " ";
    std::cout << std::endl;
    s = m.suffix().str();
  }

  return 0;
}
CodeBlocks default compiler doesn't support regex.
Could anyone suggest good IDE in linux with C++11 support (including regex)?
The IDE isn't what's limiting you, just the compiler, CodeBlocks is a good IDE imo. I would suggest installing your own, up-to-date compiler to work with CodeBlocks, it shouldn't be too hard.
http://wiki.codeblocks.org/index.php?title=Installing_a_supported_compiler#Linux should help, although I haven't used CodeBlocks on Linux only g++ itself.
(Also, not sure how outdated that wiki article is, I'm petty sure you can get clang support as well, but I don't know).
Last edited on
Tnx a lot for answers guys! I tryed to compile the same code fragment using by just creating empty .cpp file and putting same code within it, than compiled it with
g++ -std=c++11 -o exmpl example.cpp

and I got the same error message. So at least now i know that its actually compiler not CodeBlocks thats causing it. Tnx :)
GCC 4.9 or later is needed for standard regex support.
Check the version with g++ --version

When upgrading, go directly to GCC 5.1 (it is the only version with a good standard C++ library implementation.)
Thanks you guys very much! I installed 4.9 and its working now! Should have went for 5.1 but ok will do that later :)
Topic archived. No new replies allowed.