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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.