View on GitHub

Computer Architecture and Operating Systems

Course taught at Faculty of Computer Science of Higher School of Economics

Lecture 5

Strings and regular expressions

Lecture

Slides (PDF, PPTX).

Theory

Workshop

Outline

Homework

Write a program that inputs three command-line arguments:

The program finds all occurrences of the regular expression in the text and replaces all of them with the specified replacement string. The updated text is stored in a separate buffer and printed to the console in the end.

Hint: Algorithm is as follows. Allocate a buffer for the new text. Find a regular expression match. Copy to the buffer text before match. Copy to the buffer replacement. Find the next regular expression match and so on.

Note: The problem when the size of the allocated buffer is not enough to store the text can be solved by using the realloc function to allocated additional space.

References