A regular expression is a way of describing a sequence of characters. Regular expressions are a stunningly powerful computational device. However, describing the languages used to define regular expressions is well beyond the scope of this Primer. Instead, we’ll focus on how to use the C++ regular-expression library (RE library), which is part of the new library. The RE library, which is defined in the regex
header, involves several components, listed in Table 17.4.
If you are not already familiar with using regular expressions, you might want to skim this section to get an idea of the kinds of things regular expressions can do.
The regex
class represents a regular expression. Aside from initialization and assignment, regex
has few operations. The operations on regex
are listed in Table 17.6 (p. 731).
The functions regex_match
and regex_search
determine whether a given character sequence matches a given regex
. The regex_match
function returns true
if the entire input sequence matches the expression; regex_search
returns true
if there is a substring in the input sequence that matches. There is also a regex_replace
function that we’ll describe in § 17.3.4 (p. 741).
The arguments to the regex
functions are described in Table 17.5 (overleaf). These functions return a bool
and are overloaded: One version takes an additional argument of type smatch
. If present, these functions store additional information about a successful match in the given smatch
object.