Chapter 18. Search Results

Shun those studies in which the work that results dies with the worker.

The NotebooksLEONARDO DA VINCI

Suppose that you want to scan a text file encoded in HTML and extract all the code snippets. Each snippet begins with “<CODE>” and ends with “</CODE>”. The two markers are not case sensitive. In Chapter 17, we looked at a regular expression to recognize these snippets:

const char *expr = "<CODE>";

Now we need to enhance that expression, to require both markers, and to capture the text between the two markers. To do that, we add the second marker and a capture group to hold the text between the markers:

const char *expr = "<CODE>(.*)</CODE>";

After a successful match, the capture group will hold the text that was found ...

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.