Does a null match match when regex_search returns true?

Here are some quotes from the C ++ 11 standard:

11.28.3 regex_search [re.alg.search]

mis a regex_searchtype argument match_results.

2 E ff ects: Determines if re is some subsequence inside [first, last] that matches the regular expression e. Parameter flags are used to control how an expression is mapped to a character sequence. Returns true if such a sequence exists, otherwise false.

3 Postconditions: m.ready () == true in all cases. If the function returns false, then the effect on the parameter m is not defined, except that m.size () returns 0 and m.empty () returns true. Otherwise, the effects on the parameter m are given in table 143.

Table 143 indicates the following m[0].matched:

true if a match is found, and false otherwise.

The foregoing means that it is possible regex_searchto return trueand at the same time m[0].matchedbe false. Can someone please provide an example (for a regular expression pattern and text to match) that shows when this is possible?

In other words, with what values textand the refollowing program will not argue:

#include <regex>
#include <cassert>
int main()
{
    char re[] = ""; // what kind of regular expression must it be?
    char text[] = ""; // what kind of input text must it be?
    std::cmatch m;
    assert(std::regex_search(text, m, std::regex(re)) == true);
    assert(m[0].matched == false);
}
+4
2

-, ++ 11 (N3337) .

regex_search false, , , match_results , - match_results::ready, true, match_results::size, 0 match_results::empty, true.

match_results::operator[] , .

, regex_search true, , , m[0].matched true. false.

N3936, 143:

m [0].matched |

, , . :

143: m[0].matched "true, , - false". 143 - , "".

+5

143 .

, m.size() , , , m[0] ( 0 >= m.size()), m[0].matched .

, m.size() , , , m[0] - , m[0].matched . m.size() 1, m[i] i<m.size() , .

, "m[0].matched" , 143 - ( , ), .

re.results (28.10/4), , [] .size() .

+1

All Articles