You are not logged in.
Can somebody please explain to me why this code produces these results?
#include <iostream>
#include <string>
#include <regex>
int main (int argc, char** argv) {
std::regex exp;
try {
exp = std::regex("[0-9].*", std::regex_constants::basic);
} catch (const std::regex_error& e) {
std::cerr << "Error: " << e.what() << std::endl;
std::cerr << "Error code: " << e.code() << std::endl;
return 1;
}
std::cout << "created regex object" << std::endl;
for (int i = 1; i < argc; ++i) {
std::string inputString(argv[i]);
std::cout << "input string: '" << inputString << "'" << std::endl;
std::cout << (std::regex_match(inputString, exp) ? "matches" : "doesn't match") << std::endl;
}
return 0;
}
$ g++ -std=c++11 x.cpp
$ ./a.out 1 11 a 1a a1 aa
created regex object
input string: '1'
matches
input string: '11'
doesn't match
input string: 'a'
matches
input string: '1a'
doesn't match
input string: 'a1'
doesn't match
input string: 'aa'
doesn't match
Last edited by ypoluektovich (2013-05-03 11:57:07)
Offline
Eh, the answer is actually pretty disappointing.
http://gcc.gnu.org/onlinedocs/libstdc++ … s.iso.2011
Currently, almost all the regular expression stuff is not implemented yet. I'll have to use boost regex.
Offline
Or try with LLVM/Clang, they claim full C++11 support.
Offline
Or try with LLVM/Clang, they claim full C++11 support.
Just using Clang does not provide regular expression support. You need to use use clang and libc++ for that (both found in the official repositories).
Then you programme using the regex library as you would expect it to work.
Note: compile your programmes with:
clang++ -stdlib=libc++ -std=c++11 -lc++abi my_file.cpp
Clang supports all the common gcc options so any Makefiles or build systems will still function upon switching.
Last edited by mthinkcpp (2013-07-15 12:32:13)
Offline