I can't get $ (dollar sign) to work as described in C ++ 11 regular expressions. This is with ECMAScript syntax (by default).
Example (regex.cc):
#include <iostream>
#include <regex>
int main() {
if ( std::regex_search("one\ntwo", std::regex{"one$"}) ) {
std::cout << "Should match, doesn't." << std::endl;
}
if ( std::regex_search("one\ntwo", std::regex{"two$"}
, std::regex_constants::match_not_eol) ) {
std::cout << "Shouldn't match, does." << std::endl;
}
return 0;
}
Expected Result: Must match, does not.
Actual output: Should not match does.
From http://www.cplusplus.com/reference/regex/ECMAScript/ :
$ - End of line - Either this is the end of the target sequence, or precedes the line terminator.
From http://www.cplusplus.com/reference/regex/regex_search/ :
match_not_eol- Not End-Of-Line - the last character is not considered the end of the line ( "$"does not match).
Tested with Clang 3.3 and 3.4 on FreeBSD 10:
clang++ -std=c++11 -stdlib=libc++ -o regex regex.cc && ./regex
What am I missing?