+ 7
C++ regex
I'm trying to use regular expressions in c++. Example code: ///////////////////////////////////////////////////////// #include <regex> int main(){ std::regex pattern("([a-z]+)\\.txt"); return 0; } ///////////////////////////////////////////////////////// The code will compile. But when I run it I get regex_error exception. I'm using this to compile it: > g++ -std=c++11 example.cpp my compiler version is 4.8.4. Can someone help me?
1 ответ
+ 6
ECMAScript is the default syntax for the standard library's regular expressions, which doesn't support brackets.
For your regex to work, use the Basic POSIX flag:
std::regex pattern("([a-z]+)\\.txt", std::regex_constants::basic);