13. Regular Expressions
Regular expression is a language for describing text patterns. They need the header <regex>
.
Regular expressions are a powerful tool for the following tasks:
- Check if a text matches a text pattern:
std::regex_match
- Search for a text pattern in a text:
std::regex_search
- Replace a text pattern with a text:
std::regex_replace
- Iterate through all text patterns in a text:
std::regex_iterator
andstd::regex_token_iterator
C++ supports six different grammars for regular expressions. By default, the ECMAScript grammar is used. This one is the most powerful grammar of the six grammars and is quite similar to the grammar used in Perl 5. The other five grammars are the basic, extended, awk, grep and egrep grammars.