A Brief Introduction to Regular Expressions


Introduction

Regular Expressions are ubiquitous in computer science. We will study one example here: using regular expressions to specify a search pattern in the Metrowerks Editor. Such patterns help us locate appropriate information in our source code. Each regular expression is like the right hand side of an EBNF rule, although it uses a different notation and includes more options.

Below is a picture of The Find window in Metrowerks (bring it up by pressing Ctrl f or selecting Search | Find). It has a checkbox to enable/disable Regular expressions. By enabling this mode, Metrowerks interprets the Find text box according to special notation described below, in which certain characters specify not themselves, but instructions. If this mode is disabled, then every character just matches itself.

It is easy to test your knowledge of regular expressions by typing information into a small text file and then using regular expression patterns in the Find window to search it. Experiment!

Notation

Just as in EBNF, certain characters in regular expressions have special meanings while others just stand for themselves. Here is a brief discussion, with examples, of the meanings of various components in regular expressions. This material assumes that you are already familiar with EBNF.