C ++ 11 regex end-of-line doesn't match

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?

+4
1

, LWG issue 2343

,

Multiline true, $ LineTerminator.

Multiline false, $ LineTerminator.

[,,]

:

= FALSE:

libstd++ r206594

lib++ r199174

Multiline = True:

Visual Studio Express 2013

boost 1.55

: SVN libc++, IS , , LWG Multiline favor

(match_not_eol ) . Boost.regex .

+5

Source: https://habr.com/ru/post/1526249/


All Articles