I encountered a task which reuires a regex matching nothing.
C++ reference happily states that it already has such thing: http://en.cppreference.com/w/cpp/regex/basic_regex/basic_regex
1) Default constructor. Constructs an empty regular expression which will match nothing.
But in reality (clang 3.3) it happens not to be the case:
#include <string>
#include <regex>
int main(int argc, const char *argv[]) {
std::regex re1;
std::regex re2("");
std::smatch rt1, rt2;
bool r1 = std::regex_match(std::string(""), rt1, re1);
bool r2 = std::regex_match(std::string(""), rt2, re2);
std::cerr << "r1:" << r1 << ", r2:" << r2 << std::endl;
}
This program prints: r1:1, r2:1
What should mean that both regexes matched empty string.
Any idea what is wrong here and how to create "match nothing" regex ?