A regular expression specifies a text pattern for recognizing, extracting, or substituting text. In modern C++, it offers a safer alternative to hand-written parsing, whose conditions become difficult to extend and whose comments can become stale. section 4.0 section 4.8
An email-validation pattern proceeds from left to right:
- Match a username containing permitted letters, digits, and limited punctuation. section 4.8
- Match the at-sign separator and a domain containing letters or digits. section 4.8
- Match an escaped period followed by a top-level domain containing at least two letters. section 4.8
Replacing brittle email checks
A hand-coded validator checks for an at sign, a period, and nonempty sections, but admits invalid characters. A std::regex pattern used with std::regex_search expresses the permitted structure more precisely. section 4.8
Making patterns readable
A raw string such as R"(\\)" avoids the extra escaping required by an ordinary C++ string. The regular expression still needs its own escape when a character, such as a period, has special meaning. section 4.8


























