template< class BidirIt, class CharT, class Traits > bool regex_match( ... Example. #include #include #include int main() ...
std::regex_matchDefinedinheadertemplate
boolregex_match(BidirItfirst,BidirItlast,
std::match_results&m,
conststd::basic_regex&e,
std::regex_constants::match_flag_typeflags=
std::regex_constants::match_default);
(1)(sinceC++11)template
boolregex_match(BidirItfirst,BidirItlast,
conststd::basic_regex&e,
std::regex_constants::match_flag_typeflags=
std::regex_constants::match_default);
(2)(sinceC++11)template
boolregex_match(constCharT*str,
std::match_results&m,
conststd::basic_regex&e,
std::regex_constants::match_flag_typeflags=
std::regex_constants::match_default);
(3)(sinceC++11)template
boolregex_match(conststd::basic_string&s,
std::match_results<
typenamestd::basic_string::const_iterator,
Alloc
>&m,
conststd::basic_regex&e,
std::regex_constants::match_flag_typeflags=
std::regex_constants::match_default);
(4)(sinceC++11)template
boolregex_match(constCharT*str,
conststd::basic_regex&e,
std::regex_constants::match_flag_typeflags=
std::regex_constants::match_default);
(5)(sinceC++11)template
boolregex_match(conststd::basic_string&s,
conststd::basic_regex&e,
std::regex_constants::match_flag_typeflags=
std::regex_constants::match_default);
(6)(sinceC++11)template
boolregex_match(conststd::basic_string&&,
std::match_results<
typenamestd::basic_string::const_iterator,
Alloc
>&,
conststd::basic_regex&,
std::regex_constants::match_flag_typeflags=
std::regex_constants::match_default)=delete;
(7)(sinceC++14)Determinesiftheregularexpressionematchestheentiretargetcharactersequence,whichmaybespecifiedasstd::string,aC-string,oraniteratorpair.
1)Determinesifthereisamatchbetweentheregularexpressioneandtheentiretargetcharactersequence[first,last),takingintoaccounttheeffectofflags.Whendeterminingifthereisamatch,onlypotentialmatchesthatmatchtheentirecharactersequenceareconsidered.Matchresultsarereturnedinm.
2)Behavesas(1)above,omittingthematchresults.
3)Returnsstd::regex_match(str,str+std::char_traits::length(str),m,e,flags).
4)Returnsstd::regex_match(s.begin(),s.end(),m,e,flags).
5)Returnsstd::regex_match(str,str+std::char_traits::length(str),e,flags).
6)Returnsstd::regex_match(s.begin(),s.end(),e,flags).
7)Theoverload4isprohibitedfromacceptingtemporarystrings,otherwisethisfunctionpopulatesmatch_resultsmwithstringiteratorsthatbecomeinvalidimmediately.Notethatregex_matchwillonlysuccessfullymatcharegularexpressiontoanentirecharactersequence,whereasstd::regex_searchwillsuccessfullymatchsubsequences.
Parametersfirst,last-thetargetcharacterrangetoapplytheregexto,givenasiterators
m-thematchresults
str-thetargetstring,givenasanull-terminatedC-stylestring
s-thetargetstring,givenasastd::basic_string
e-theregularexpression
flags-flagsusedtodeterminehowthematchwillbeperformed
Typerequirements
-BidirItmustmeettherequirementsofLegacyBidirectionalIterator.
ReturnvalueReturnstrueifamatchexists,falseotherwise.Ineithercase,theobjectmisupdated,asfollows:
Ifthematchdoesnotexist:
m.ready()==true
m.empty()==true
m.size()==0
Ifthematchexists:
m.ready()true
m.empty()false
m.size()numberofmarkedsubexpressionsplus1,thatis,1+e.mark_count()
m.prefix().firstfirst
m.prefix().secondfirst
m.prefix().matchedfalse(thematchprefixisempty)
m.suffix().firstlast
m.suffix().secondlast
m.suffix().matchedfalse(thematchsuffixisempty)
m[0].firstfirst
m[0].secondlast
m[0].matchedtrue(theentiresequenceismatched)
m[n].firstthestartofthesequencethatmatchedmarkedsub-expressionn,orlastifthesubexpressiondidnotparticipateinthematch
m[n].secondtheendofthesequencethatmatchedmarkedsub-expressionn,orlastifthesubexpressiondidnotparticipateinthematch
m[n].matchedtrueifsub-expressionnparticipatedinthematch,falseotherwise
NotesBecauseregex_matchonlyconsidersfullmatches,thesameregexmaygivedifferentmatchesbetweenregex_matchandstd::regex_search:
std::regexre("Get|GetValue");
std::cmatchm;
std::regex_search("GetValue",m,re);//returnstrue,andm[0]contains"Get"
std::regex_match("GetValue",m,re);//returnstrue,andm[0]contains"GetValue"
std::regex_search("GetValues",m,re);//returnstrue,andm[0]contains"Get"
std::regex_match("GetValues",m,re);//returnsfalseExample#include
#include
#include
intmain()
{
//Simpleregularexpressionmatching
conststd::stringfnames[]={"foo.txt","bar.txt","baz.dat","zoidberg"};
conststd::regextxt_regex("[a-z]+\\.txt");
for(constauto&fname:fnames){
std::cout<