O'Reilly logo

C++ Primer, Fifth Edition by Barbara E. Moo, Josée Lajoie, Stanley B. Lippman

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

17.3.1. Using the Regular Expression Library

As a fairly simple example, we’ll look for words that violate a well-known spelling rule of thumb, “i before e except after c”:

// find the characters ei that follow a character other than cstring pattern("[^c]ei");// we want the whole word in which our pattern appearspattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";regex r(pattern); // construct a regex to find patternsmatch results;   // define an object to hold the results of a search// define a string that has text that does and doesn't match patternstring test_str = "receipt freind theif receive";// use r to find a match to pattern in test_strif (regex_search(test_str, results, r)) // if there is a match    cout << results.str() << endl;      // ...

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