Defining Regular Expressions

At the highest level, a regular expression is one or more branches separated by the vertical bar character (|). This character is considered to have the properties of a logical-OR. Any of the branches could match with an evaluated string. Table 16-1 provides a few examples.

Each branch contains one or more atoms. These atoms may be followed by characters that modify the number of times the atom may be matched in succession. An asterisk (*) means the atom can match any number of times. A plus sign (+) means the atom must match at least once. A question mark (?) signifies that the atom may match once or not at all.

Alternatively, the atom may be bound, which means it is followed by curly braces, { and }, that contain ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.