Search code examples
c++regextr1

tr/regex c++ library - definition of regex pattern


How should i define the regex pattern, when i use the tr1/regex library?

#include <tr1/regex>

const regex pattern("[^-]-[^-]");

is not working... When compiling i get error: ‘regex’ does not name a type


Solution

  • regex is in the tr1 namespace so you either need to declare that you are using tr1 or specify that regex is in the tr1 namespace:

    using namespace tr1;
    

    or

    const tr1::regex pattern("[^-]-[^-]");