August 2000
Intermediate to advanced
800 pages
13h 15m
English
The basic function for executing regular expressions is ereg. This function evaluates a string against a regular expression, returning TRUE if the pattern described by the regular expression appears in the string. In this minimal form, you can check that a string conforms to a certain form. For example, you can ensure that a U.S. postal zip code is in the proper form of five digits followed by a dash and four more digits. Listing 16.2 demonstrates this idea.
| Sample | Description |
|---|---|
| a.c | Matches aac, abc, acc, ... — Any three-character string beginning with an a and ending with a c. |
| ^a.* | Matches any string starting with an a. |
| [a-c]*x$ | Matches x, ax, bx, abax, abcx — ... |
Read now
Unlock full access