O'Reilly logo

Beginning C++ Programming by Richard Grimes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required