[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<class BidirectionalIterator, class Allocator, class charT, class traits>
  bool regex_search(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);
`

[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)<br>**Element** | **Value** |
| --- | --- |
| [ð](#tab:re.alg.search-row-2)<br>m.size() | 1 + e.mark_count() |
| [ð](#tab:re.alg.search-row-3)<br>m.empty() | false |
| [ð](#tab:re.alg.search-row-4)<br>m.prefix().first | first |
| [ð](#tab:re.alg.search-row-5)<br>m.prefix().second | m[0].first |
| [ð](#tab:re.alg.search-row-6)<br>m.prefix().matched | m.prefix().first != m.prefix().second |
| [ð](#tab:re.alg.search-row-7)<br>m.suffix().first | m[0].second |
| [ð](#tab:re.alg.search-row-8)<br>m.suffix().second | last |
| [ð](#tab:re.alg.search-row-9)<br>m.suffix().matched | m.suffix().first != m.suffix().second |
| [ð](#tab:re.alg.search-row-10)<br>m[0].first | The start of the sequence of characters that matched the regular expression |
| [ð](#tab:re.alg.search-row-11)<br>m[0].second | The end of the sequence of characters that matched the regular expression |
| [ð](#tab:re.alg.search-row-12)<br>m[0].matched | true |
| [ð](#tab:re.alg.search-row-13)<br>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)<br>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)<br>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)<br>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)<br>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<class charT, class Allocator, class traits>
  bool regex_search(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);
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L12022)

*Returns*: regex_search(str, str + char_traits<charT>​::​length(str), m, e, flags)[.](#4.sentence-1)

[ð](#lib:regex_search__)

`template<class ST, class SA, class Allocator, class charT, class traits>
  bool regex_search(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);
`

[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<class BidirectionalIterator, class charT, class traits>
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
                    const basic_regex<charT, traits>& 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<BidirectionalIterator> and returningregex_search(first, last, what, e, flags)[.](#6.sentence-1)

[ð](#lib:regex_search____)

`template<class charT, class traits>
  bool regex_search(const charT* str,
                    const basic_regex<charT, traits>& 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<charT>​::​length(str), e, flags)[.](#7.sentence-1)

[ð](#lib:regex_search_____)

`template<class ST, class SA, class charT, class traits>
  bool regex_search(const basic_string<charT, ST, SA>& s,
                    const basic_regex<charT, traits>& 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)
