Matching expressions

Once you have constructed a regex object you can pass it to the methods in the <regex> library to search for the pattern in a string. The regex_match function is passed in a string (C or C++) or iterators to a range of characters in a container and a constructed regex object. In its simplest form, the function will return true only if there is an exact match, that is, the expression exactly matches the search string:

    regex rx("[at]"); // search for either a or t     cout << boolalpha;     cout << regex_match("a", rx) << "n";  // true     cout << regex_match("a", rx) << "n";  // true     cout << regex_match("at", rx) << "n"; // false

In the previous code, the search expression is for a single character in the range given (a or t), ...

Get Modern C++: Efficient and Scalable Application Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.