22.3. 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 22.1 provides a few examples.

Table 22.1. Branches in a Regular Expression
SampleDescription
AppleMatches the word apple.
apple|ballMatches either apple or ball.
begin|end|breakMatches either begin, end, or break.

Each branch contains one or more atoms. Characters that modify the number of times the atom may be matched in succession may follow these atoms. An asterisk (*) means the atom can match any number of times. A plus sign (+) means the atom must match at least once. ...

Get Core PHP Programming, Third Edition 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.