Regular expressions
suggest changeIntroduction
Regular expressions (sometimes called regexes or regexps) use textual patterns to describe strings to match.
Regular Expressions, introduced in c++11, may optionally support a return array of matched strings or another textual syntax defining how to replace matched patterns in strings operated upon.
Syntax
- regex_match // Returns whether the entire character sequence was matched by the regex, optionally capturing into a match object
- regex_search // Returns whether a portion of the character sequence was matched by the regex, optionally capturing into a match object
- regex_replace // Returns the input character sequence as modified by a regex via a replacement format string
- regex_token_iterator // Initialized with a character sequence defined by iterators, a list of capture indexes to iterate over, and a regex. Dereferencing returns the currently indexed match of the regex. Incrementing moves to the next capture index or if currently at the last index, resets the index and finds the next occurrence of a regex match in the character sequence
- regex_iterator // Initialized with a character sequence defined by iterators and a regex. Dereferencing returns the portion of the character sequence the entire regex currently matches. Incrementing finds the next occurrence of a regex match in the character sequence
Parameters
| Signature | Description |
|---|---|
bool regex_match(BidirectionalIterator first, BidirectionalIterator last, smatch& sm, const regex& re, regex_constants::match_flag_type flags) |
BidirectionalIterator is any character iterator that provides increment and decrement operators. The match argument must be a match_results for that iterator type. smatch is correct only for std::string iterators, and cmatch is correct only for const char*. The match argument may be omitted if the results of the regex are not needed. Returns whether re matches the entire character sequence defined by first and last. |
bool regex_match(const string& str, smatch& sm, const regex& re, regex_constants::match_flag_type flags) |
string may be either a const char* or an lvalue string. Overloads that take an rvalue string together with a match_results are deleted, because the match would refer to a temporary. smatch may be cmatch or any other variant of match_results that accepts the type of str. The smatch argument may be omitted if the results of the regex are not needed. Returns whether re matches the entire character sequence defined by str. |
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents