function template
<regex>
std::regex_search C-strings (1)template <class charT, class traits> bool regex_search (const charT* s, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);strings (2)
template <class ST, class SA, char charT, class traits> bool regex_search (const basic_string<charT,ST,SA>& s, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);ranges (3)
template <class BidirectionalIterator, class charT, class traits> bool regex_search (BidirectionalIterator first, BidirectionalIterator last, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);with match_results (4,5,6)
template <class charT, class Alloc, class traits> bool regex_search (const charT* s, match_results<const charT*, Alloc>& m, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);template <class ST, class SA, class Alloc, class charT, class traits> bool regex_search (const basic_string<charT,ST,SA>& s, match_results<typename basic_string<charT,ST,SA>::const_iterator,Alloc>& m, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);template <class BidirectionalIterator, class Alloc, class charT, class traits> bool regex_search (BidirectionalIterator first, BidirectionalIterator last, match_results<BidirectionalIterator, Alloc>& m, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);C-strings (1)
template <class charT, class traits> bool regex_search (const charT* s, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);strings (2)
template <class ST, class SA, char charT, class traits> bool regex_search (const basic_string<charT,ST,SA>& s, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);ranges (3)
template <class BidirectionalIterator, class charT, class traits> bool regex_search (BidirectionalIterator first, BidirectionalIterator last, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);with match_results (4,5,6)
template <class charT, class Alloc, class traits> bool regex_search (const charT* s, match_results<const charT*, Alloc>& m, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);template <class ST, class SA, class Alloc, class charT, class traits> bool regex_search (const basic_string<charT,ST,SA>& s, match_results<typename basic_string<charT,ST,SA>::const_iterator,Alloc>& m, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);template <class BidirectionalIterator, class Alloc, class charT, class traits> bool regex_search (BidirectionalIterator first, BidirectionalIterator last, match_results<BidirectionalIterator, Alloc>& m, const basic_regex<charT,traits>& rgx, regex_constants::match_flag_type flags = regex_constants::match_default);moving string (deleted) (7)
template <class ST, class SA, class Alloc, class charT, class traits> bool regex_search (const basic_string<charT,ST,SA>&&, match_results<typename basic_string<charT,ST,SA>::const_iterator,Alloc>&, const basic_regex<charT,traits>&, regex_constants::match_flag_type=regex_constants::match_default) = delete;
Search sequence
Returns whether some sub-sequence in the target sequence (the subject) matches the regular expression rgx (the pattern). The target sequence is either s or the character sequence between first and last, depending on the version used.The versions 4, 5 and 6, are identical to 1, 2 and 3 respectively, except that they take an object of a match_results type as argument, which is filled with information about the match results.
An optional parameter, flags, allows to specify options on how to search for the expression.
This function returns true if the expression is found anywhere in the target sequence, even if the sequence contains more characters that are not part of the match before or after the match. For a function that returns true only when the entire sequence matches, see regex_match.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// regex_search example
#include <iostream>
#include <string>
#include <regex>
int main ()
{
std::string s ("this subject has a submarine as a subsequence");
std::smatch m;
std::regex e ("\\b(sub)([^ ]*)"); // matches words beginning by "sub"
std::cout << "Target sequence: " << s << std::endl;
std::cout << "Regular expression: /\\b(sub)([^ ]*)/" << std::endl;
std::cout << "The following matches and submatches were found:" << std::endl;
while (std::regex_search (s,m,e)) {
for (auto x:m) std::cout << x << " ";
std::cout << std::endl;
s = m.suffix().str();
}
return 0;
}
Target sequence: this subject has a submarine as subsequence Regular expression: /\b(sub)([^ ]*)/ The following matches and submatches were found: subject sub ject submarine sub marine subsequence sub sequence
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4