Chapter 19. Repetitive Searches
There are only two or three human stories, and they go on repeating themselves as fiercely as if they had never happened before.
O Pioneers!WILLA CATHER
Did you spot the problem with the example program that searched for code snippets in a text file at the beginning of Chapter 18? In lines that have multiple code snippets, everything between the first “<CODE>”
and the last “</CODE>”
is listed as a single snippet. To separate multiple snippets, we first have to change the regular expression a bit so that it doesn’t swallow multiple snippets. In this case, we can replace the “.*”
with a nongreedy repetition:
string expr = " <CODE>(.*?) </CODE>";
Now, to resume searching after the text that matched, we have to change ...
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.