31 Regular expressions library [re]

31.11 Regular expression algorithms [re.alg]

31.11.2 regex_­match [re.alg.match]

template <class BidirectionalIterator, class Allocator, class charT, class traits> bool regex_match(BidirectionalIterator first, BidirectionalIterator last, match_results<BidirectionalIterator, Allocator>& m, const basic_regex<charT, traits>& e, regex_constants::match_flag_type flags = regex_constants::match_default);

Requires: Тип BidirectionalIterator должен удовлетворять требованиям а Bidirectional Iterator.

Effects: Определяет, есть ли совпадение между регулярным выражением eи всей последовательностью символов [first, last). Параметр flags используется для управления тем, как выражение сопоставляется с последовательностью символов. При определении совпадения учитываются только потенциальные совпадения, соответствующие всей последовательности символов. Возвращает, true если такое совпадение существует, в false противном случае. [Example:

std::regex re("Get|GetValue");
std::cmatch m;
regex_search("GetValue", m, re);	// returns true, and m[0] contains "Get"
regex_match ("GetValue", m, re);	// returns true, and m[0] contains "GetValue"
regex_search("GetValues", m, re);	// returns true, and m[0] contains "Get"
regex_match ("GetValues", m, re);	// returns false

end example]

Postconditions: m.ready() == true в любом случае. Если функция возвращает результат false, то влияние на параметр m не определено, за исключением того, что m.size() возвращается 0 и m.empty() возвращается true. В противном случае влияние на параметр m приведено в таблице 135.

Таблица 135 - Эффекты regex_­match алгоритма
ЭлементЦенить
m.size() 1 + e.mark_­count()
m.empty() false
m.prefix().first first
m.prefix().second first
m.prefix().matched false
m.suffix().first last
m.suffix().second last
m.suffix().matched false
m[0].first first
m[0].second last
m[0].matched true
m[n].first Для всех целых чисел 0 < n < m.size()- начало последовательности, соответствующей подвыражению n. В качестве альтернативы, если подвыражение n не участвовало в сопоставлении, тогда last.
m[n].second Для всех целых чисел 0 < n < m.size()- конец последовательности, соответствующей подвыражению n. В качестве альтернативы, если подвыражение n не участвовало в сопоставлении, тогда last.
m[n].matched Для всех целых чисел 0 < n < m.size(), true если n в совпадении участвовало подвыражение, в false противном случае.

template <class BidirectionalIterator, class charT, class traits> bool regex_match(BidirectionalIterator first, BidirectionalIterator last, const basic_regex<charT, traits>& e, regex_constants::match_flag_type flags = regex_constants::match_default);

Effects: Ведет себя «как будто», создавая экземпляр match_­results<BidirectionalIterator> what, а затем возвращая результат regex_­match(first, last, what, e, flags).

template <class charT, class Allocator, class traits> bool regex_match(const charT* str, match_results<const charT*, Allocator>& m, const basic_regex<charT, traits>& e, regex_constants::match_flag_type flags = regex_constants::match_default);

Returns: regex_­match(str, str + char_­traits<charT>​::​length(str), m, e, flags).

template <class ST, class SA, class Allocator, class charT, class traits> bool regex_match(const basic_string<charT, ST, SA>& s, match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, const basic_regex<charT, traits>& e, regex_constants::match_flag_type flags = regex_constants::match_default);

Returns: regex_­match(s.begin(), s.end(), m, e, flags).

template <class charT, class traits> bool regex_match(const charT* str, const basic_regex<charT, traits>& e, regex_constants::match_flag_type flags = regex_constants::match_default);

Returns: regex_­match(str, str + char_­traits<charT>​::​length(str), e, flags)

template <class ST, class SA, class charT, class traits> bool regex_match(const basic_string<charT, ST, SA>& s, const basic_regex<charT, traits>& e, regex_constants::match_flag_type flags = regex_constants::match_default);

Returns: regex_­match(s.begin(), s.end(), e, flags).