1.8. Regular Expressions
Regular expressions are used to specify string patterns. You can use regular expressions whenever you need to locate strings that match a particular pattern. For example, one of our sample programs locates all hyperlinks in an HTML file by looking for strings of the pattern
Of course, for specifying a pattern, the
... notation is not precise enough. You need to specify exactly what sequence of characters is a legal match, using a special syntax to describe a pattern.
Here is a simple example. The regular expression
matches any string of the following form:
• The first letter is a
• The next three letters are
• The remainder of the string consists of one or more arbitrary characters. ...