function template
<regex>
std::regex_match C-strings (1)template <class charT, class traits> bool regex_match (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_match (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_match (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_match (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_match (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_match (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_match (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_match (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_match (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_match (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_match (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_match (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_match (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;
Match sequence
Returns whether the target sequence matches the regular expression rgx. 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.
Deleting the signature with a moving string (7) prevents the construction with a temporary string object.
An optional parameter, flags, allows to specify options on how to match the expression.
The entire target sequence must match the regular expression for this function to return true (i.e., without any additional characters before or after the match). For a function that returns true when the match is only part of the sequence, see regex_search.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// regex_match example
#include <iostream>
#include <string>
#include <regex>
int main ()
{
if (std::regex_match ("subject", std::regex("(sub)(.*)") ))
std::cout << "string literal matched\n";
const char cstr[] = "subject";
std::string s ("subject");
std::regex e ("(sub)(.*)");
if (std::regex_match (s,e))
std::cout << "string object matched\n";
if ( std::regex_match ( s.begin(), s.end(), e ) )
std::cout << "range matched\n";
std::cmatch cm; // same as std::match_results<const char*> cm;
std::regex_match (cstr,cm,e);
std::cout << "string literal with " << cm.size() << " matches\n";
std::smatch sm; // same as std::match_results<string::const_iterator> sm;
std::regex_match (s,sm,e);
std::cout << "string object with " << sm.size() << " matches\n";
std::regex_match ( s.cbegin(), s.cend(), sm, e);
std::cout << "range with " << sm.size() << " matches\n";
// using explicit flags:
std::regex_match ( cstr, cm, e, std::regex_constants::match_default );
std::cout << "the matches were: ";
for (unsigned i=0; i<cm.size(); ++i) {
std::cout << "[" << cm[i] << "] ";
}
std::cout << std::endl;
return 0;
}
string literal matched string object matched range matched string literal with 3 matches string object with 3 matches range with 3 matches the matches were: [subject] [sub] [ject]
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