February 2004
Intermediate to advanced
160 pages
2h 27m
English
A powerful yet infrequently used feature of the regular expression language is the capability to embed conditional processing within an expression. This lesson will explore this topic.
(123)456-7890 and 123-456-7890 are both acceptable presentation formats for North American phone numbers. 1234567890, (123)-456-7890, and (123-456-7890 all contain the correct number of digits, but are badly formatted. How could you write a regular expression to match only the acceptable formats and not any others?
This is not a trivial problem; consider this obvious solution:
![]()
123-456-7890(123)456-7890(123)-456-7890 ...
Read now
Unlock full access