Regular Expressions

Definitions and uses

Regular expressions enable our program to "search" text.

Given a string and a pattern (template), our program can perform several tasks:

  1. Determine whether the string contains the pattern, and return "true" or "false".

  2. Extract from the string a substring that matches the pattern.

  3. Look for the pattern in the string and replace it with something else.

  4. Using the split function: look for all appearances of the pattern in the string and extract the parts of the string that are not matching the pattern. In this case, the pattern actually defines the delimiter.

In all these cases we say that the program matches the pattern against the string.

The patterns themselves are specified using regular expressions.


Table of Contents.
Next.