6. Regular Expressions

Note

Project: Validate a phone number using regular expressions.

Most introductory programming books don’t include an entire chapter on regular expressions because regular expressions can be intimidating. As a result, many programmers choose to never learn regular expressions. Although other tools can do much of what regular expressions can do, they don’t do the job as well. You can drive nails with the backside of a screwdriver, for example, but using a hammer is so much easier. For certain jobs, nothing but regular expressions work. Becoming comfortable with regular expressions early will benefit you as long as you program.

Having said that, I should mention that regular expressions are hard. They are terse and can ...

Get Learning to Program 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.