Chapter 17. Searching

There are and can be only two ways of searching into and discovering truth.

Novum OrganumFRANCIS BACON

Suppose that you want to scan a text file encoded in HTML and extract all the lines that contain code snippets. Each snippet begins with “<CODE>” and ends with “</CODE>”. The two markers are not case sensitive. For now, let’s assume that no snippet is longer than one line. This means that we need to search only for lines that contain the first marker, so we can use this text to define a regular expression for the search:

const char *expr = "<CODE>";

It’s easy to read a file one line at a time, so we don’t need to do anything more sophisticated in the regular expression to pick out lines. Simply read a line and see whether ...

Get The C++ Standard Library Extensions A Tutorial and Reference now with O’Reilly online learning.

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