Regular expressions are a standardized way to express patterns to be matched against sequences of characters. The standard C++ library provides support for ...
Search:
Reference
header
RegularExpressions
Regularexpressionsareastandardizedwaytoexpresspatternstobematchedagainstsequencesofcharacters.
ThestandardC++libraryprovidessupportforregularexpressionsintheheaderthroughaseriesofoperations.Alltheseoperationsmakeuseofsometypicalregexparameters:
Targetsequence(subject):Thesequenceofcharacterssearchedforthepattern.Generally,thisisarangespecifiedbytwoiterators,butsomefunctionsalsoacceptac-stringorastringobjectinstead.
Regularexpression(pattern):Thepatternwhichissearchedforinthetargetsequence.Thismustbeanobjectofabasic_regextype(suchasregex),generallyconstructedfromastringwithaspecialsyntaxthatdescribeswhatconstitutesamatch(seeECMAScriptsyntax).
Matchesarray:Someoperationsallowtoretrieveinformationaboutmatches.Thisinformationisstoredinoneofthespecialmatch_resultsarraytypes(suchascmatchorsmatch).
Replacementstring:Someoperationscanreplacematches.Thesereplacementsarespecifiedinstringsthatallowforaspecialformat(seeECMAScriptsyntax).
Regexoperations
Regexoperationsareperformedusingeitherfunctionsorspecialiteratoradaptors:
Functions:
regex_matchMatchsequence(functiontemplate
)regex_searchSearchsequence(functiontemplate
)regex_replaceReplacematchedsequence(functiontemplate
)
Iteratortypes:
regex_iteratorRegexiterator(classtemplate
)regex_token_iteratorRegextokeniterator(classtemplate
)
Classes
Theregexfunctionsanditeratorsmakeheavyuseofasetofsupportingtypesasargumentsandreturnvalues:
Basictypes:
basic_regexRegularexpression(classtemplate
)match_resultsMatchresults(classtemplate
)sub_matchSub-expressionmatch(classtemplate
)regex_traitsRegextraits(classtemplate
)regex_errorRegexexception(class
)
Someofthesetypesaretemplates,andhavealiasesfortheirmostcommoninstantiations:
basic_regexinstantiations:
regexRegex(class
)wregexRegexforwchar_t(class
)
match_resultsinstantiations:
cmatchmatch_resultsforstringliterals(class
)wcmatchmatch_resultsforwidestringliterals(class
)smatchmatch_resultsforstringobjects(class
)wsmatchmatch_resultsforwidestringobjects(class
)
sub_matchinstantiations:
csub_matchsub_matchforstringliterals(class
)wcsub_matchsub_matchforwidestringliterals(class
)ssub_matchsub_matchforstrings(class
)wssub_matchsub_matchforwidestrings(class
)
Namespaces
Thisheaderalsodefinesanamespace,regex_constants,underwhichallconstantvaluestobeusedbythelibraryarelocated:
regex_constantsregexconstants(namespace
)
Grammar
Regularexpressionsfollowverystrictgrammars.Bydefault,thefunctionsinthislibraryusetheECMAScriptgrammar:
ECMAScriptsyntaxECMAScriptregularexpressionspatternsyntax(syntaxspecifications
)
Otherfunctions
beginIteratortobeginning(functiontemplate
)endIteratortoend(functiontemplate
)
C++
Information
Tutorials
Reference
Articles
Forum
Reference
Clibrary:
(assert.h)
(ctype.h)
(errno.h)
(fenv.h)
(float.h)
(inttypes.h)
(iso646.h)
(limits.h)
(locale.h)
(math.h)
(setjmp.h)
(signal.h)
(stdarg.h)
(stdbool.h)
(stddef.h)
(stdint.h)
(stdio.h)
(stdlib.h)
(string.h)
(tgmath.h)
(time.h)
(uchar.h)
(wchar.h)
(wctype.h)
Containers: