Learning Boost 6
Regex 1
Overview
Template class:
l Basic_Regex is used to save a "regular expression" class.
l Sub_match inherits to the PAIR
l Match_results sub_match's container used to represent all results of a search or match algorithm, similar to Vector
algorithm:
l Regex_math matching algorithm, test whether a string matches a regular pattern and returns the result via Match_Results.
l Regex_find lookup algorithm, look up a string of strings and regular matching strings, and return the result via Match_Results.
l Regex_Format Replacement Algorithm, find all matching regular strings in the string, and replace it with the "Formatted character" string.
Iterator:
l Regex_iterator enumerates all matching strings in a string, and the result of Regex_iterator is equivalent to Match_Results.
l Regex_token_iterator enumerates all matching strings in a string, and the result of Regex_iterator is equivalent to sub_match.
Detail
l Basic_Regex
Template
Class Basic_Regex;
Typedef Basic_Regex
Typedef Basic_Regex
Obviously, Chart is a regular character type, Regex and Wregex are two specializations of Basic_Regex.
Note that the regular character type is the same as the character type of the string that needs to be matched. For example: You cannot use String and Wregex to use String and Wregex in the regex_find algorithm, either String and Regex, or WSTRING and WREGEX.
Constructor:
Basic_Regex Re Producing Empty Regular Basic_Regex RE (STR) Regular Formula is STR, STR can be BASIC_STRING, or a CHAR * string ending ended. Basic_Regex RE (RE2) Copy Construction. Basic_Regex RE (STR, FLAG) Regular Form Form Formula is Str, using the FLAG syntax option, Flag is a set of constants. For example: ICase can make regular matches ignore cases. Basic_Regex RE (BEG, END) uses the iterator constructor regular. Can be a Basic_String iterator or const char *. Basic_Regex RE (BEG, END, FLAG) uses iterator constructs regular, Flag is a syntax option.
Common grammar options:
Regex_constants :: Normal
The default syntax. Compliance with the regularity in EMCAScript, JavaScript.
Regex_constants :: ics
Ignore the case when you match.
Regex_constants :: Nosubs
Do not save the matching substrings into the Match_Results structure.
Regex_constants :: Collate
For [A-B] matches, consider the area
The syntax options are combined by or calculate. These grammar options in Basic_Regex have also been defined, so you can write a regex :: normal, which is better than REGEX_CONSTANTS! J
Assign member functions:
Re.assign (RE2)
Copy a regular style
Re.assign (STR)
Regularity is STR.
Re.assign (STR, FLAG)
Regularity is Str, use the FLAG grammatical option, Flag is a combination of constants.
Re.assign (Beg, End)
Use iterators to construct regularly.
Re.assign (Beg, End, Flag)
Use iterators to construct regularly, FLAG is a grammatical option.
In fact, Basic_Regex is very useful and Basic_String is very similar, because the regular expression is also a string!
Iterator:
Regex :: Iterator IT
Type of standing device, const_iterator
Re.begin ()
Returns the hemonds! Const_iterator
RE.End ()
No reverse iterator.
For example: Copy (Re.begin (), RE.END (), Ostream_IstRerator
other:
Re.size ()
Regular expression length, the length of the STR.
Re.max_size ()
The maximum length of the regular expression.
Re.empty ()
Is the length of 0
Re.mark_count ()
Returns the number of regularly, in general, the small parentheses logs 1. In Boost.Regex, use small brackets, please see the algorithm below for details.
Re.flags ()
Return to the syntax option.
Cout << Re
Regularly forming stream output, equivalent to the COPY algorithm of the above example.
SWAP
Member function, global functions have
Re.imbue (LOC)
Set Local to LOC, return to the original Local
Re.getloc ()
Get the current Local
==,! =, <, <=,>,> =
Compare operational operator overload
l sub_match
Sub_match is an iterator group that represents a match in the regular style.
Template
Class Sub_match: Public Std :: Pair
Boost does not provide any specialization of sub_match because we will not show a sub_match variable. SUB_MATCH is an element as a match_results. For example: Match_Results's Operator [] and iterator returns a special Sub_Match.
Unique member variable:
Bool matched does match.
Member function:
Length () returns the length, that is, the distance between the two iterators. Operator Basic_String
There is also a heavy load of a large pile of comparison operators, and there is not much to say.
l Match_Results
Match_Results is equivalent to the container of SUB_MATCH to indicate the return result of the regular algorithm.
Template Class allocator = allocator TYPEDEF MATCH_RESULTS TYPEDEF MATCH_RESULTS TYPEDEF MATCH_RESULTS TYPEDEF MATCH_RESULTS The statement is very simple, there are four specializations can be used directly, but you should pay attention to the match_results used by the string and char * strings. Member function: m.size () capacity. M.MAX_SIZE () maximum capacity. The M.empty () is 0. m [n] Nth element, that is, sub_match m.prefix () returns sub_match, the prefix, the beginning of the string to the beginning of the first match. M.Suffix () Returns the end of the sub_match representing the suffix, the last matching end of the suffix to the end of the string. M.Length (n) returns the length of the nth element, ie M [n] .size (). M.Position (n) Returns the location of the nth element. COUT << M stream output, outputs the entire match, equivalent to cout << m [0]. Because the 0th element is the entire match, please see the explanation below for details. M.Format (FMTSTR) uses formatted strings, format the results, returns string M.Format (FMTSTR, FLAGS) to use formatted strings, format results, return strings, and Flags is formatted options. M.Format (OUT, FMTSTR) is the same, but the output iterator output is used. M.Format (Out.fmtstr, Flags) is the same, but the output iterator output is used. Iterator: SMATCH :: Iterator iterator, heteramatizer smatch :: const_iterator is the same as the upper m.begin () returns the heterammill m.end () (To be continued, the algorithm is said)