[re.alg.search] # 28 Text processing library [[text]](./#text) ## 28.6 Regular expressions library [[re]](re#alg.search) ### 28.6.10 Regular expression algorithms [[re.alg]](re.alg#search) #### 28.6.10.3 regex_search [re.alg.search] [🔗](#lib:regex_search) `template bool regex_search(BidirectionalIterator first, BidirectionalIterator last, match_results& m, const basic_regex& e, regex_constants::match_flag_type flags = regex_constants::match_default); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11926) *Preconditions*: BidirectionalIterator models[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") ([[iterator.concept.bidir]](iterator.concept.bidir "24.3.4.12 Concept bidirectional_­iterator"))[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11931) *Effects*: Determines whether there is some sub-sequence within [first, last) that matches the regular expression e[.](#2.sentence-1) The parameter flags is used to control how the expression is matched against the character sequence[.](#2.sentence-2) Returns true if such a sequence exists, false otherwise[.](#2.sentence-3) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11938) *Postconditions*: m.ready() == true in all cases[.](#3.sentence-1) If the function returns false, then the effect on parameter m is unspecified except that m.size() returns 0 and m.empty() returns true[.](#3.sentence-2) Otherwise the effects on parameter m are given in Table [124](#tab:re.alg.search "Table 124: Effects of regex_­search algorithm")[.](#3.sentence-3) Table [124](#tab:re.alg.search) — Effects of regex_search algorithm [[tab:re.alg.search]](./tab:re.alg.search) | [🔗](#tab:re.alg.search-row-1)
**Element** | **Value** | | --- | --- | | [🔗](#tab:re.alg.search-row-2)
m.size() | 1 + e.mark_count() | | [🔗](#tab:re.alg.search-row-3)
m.empty() | false | | [🔗](#tab:re.alg.search-row-4)
m.prefix().first | first | | [🔗](#tab:re.alg.search-row-5)
m.prefix().second | m[0].first | | [🔗](#tab:re.alg.search-row-6)
m.prefix().matched | m.prefix().first != m.prefix().second | | [🔗](#tab:re.alg.search-row-7)
m.suffix().first | m[0].second | | [🔗](#tab:re.alg.search-row-8)
m.suffix().second | last | | [🔗](#tab:re.alg.search-row-9)
m.suffix().matched | m.suffix().first != m.suffix().second | | [🔗](#tab:re.alg.search-row-10)
m[0].first | The start of the sequence of characters that matched the regular expression | | [🔗](#tab:re.alg.search-row-11)
m[0].second | The end of the sequence of characters that matched the regular expression | | [🔗](#tab:re.alg.search-row-12)
m[0].matched | true | | [🔗](#tab:re.alg.search-row-13)
m[n].first | For all integers 0 < n < m.size(), the start of the sequence that matched sub-expression n[.](#tab:re.alg.search-row-13-column-2-sentence-1)
Alternatively, if sub-expression n did not participate in the match, then last[.](#tab:re.alg.search-row-13-column-2-sentence-2) | | [🔗](#tab:re.alg.search-row-14)
m[n].second | For all integers 0 < n < m.size(), the end of the sequence that matched sub-expression n[.](#tab:re.alg.search-row-14-column-2-sentence-1)
Alternatively, if sub-expression n did not participate in the match, then last[.](#tab:re.alg.search-row-14-column-2-sentence-2) | | [🔗](#tab:re.alg.search-row-15)
m[n].matched | For all integers 0 < n < m.size(), true if sub-expression n participated in the match, false otherwise[.](#tab:re.alg.search-row-15-column-2-sentence-1) | [🔗](#lib:regex_search_) `template bool regex_search(const charT* str, match_results& m, const basic_regex& e, regex_constants::match_flag_type flags = regex_constants::match_default); ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12022) *Returns*: regex_search(str, str + char_traits​::​length(str), m, e, flags)[.](#4.sentence-1) [🔗](#lib:regex_search__) `template bool regex_search(const basic_string& s, match_results::const_iterator, Allocator>& m, const basic_regex& e, regex_constants::match_flag_type flags = regex_constants::match_default); ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12038) *Returns*: regex_search(s.begin(), s.end(), m, e, flags)[.](#5.sentence-1) [🔗](#lib:regex_search___) `template bool regex_search(BidirectionalIterator first, BidirectionalIterator last, const basic_regex& e, regex_constants::match_flag_type flags = regex_constants::match_default); ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12052) *Effects*: Behaves “as if” by constructing an object what of type match_results and returningregex_search(first, last, what, e, flags)[.](#6.sentence-1) [🔗](#lib:regex_search____) `template bool regex_search(const charT* str, const basic_regex& e, regex_constants::match_flag_type flags = regex_constants::match_default); ` [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12068) *Returns*: regex_search(str, str + char_traits​::​length(str), e, flags)[.](#7.sentence-1) [🔗](#lib:regex_search_____) `template bool regex_search(const basic_string& s, const basic_regex& e, regex_constants::match_flag_type flags = regex_constants::match_default); ` [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12082) *Returns*: regex_search(s.begin(), s.end(), e, flags)[.](#8.sentence-1)