Appendix A. Answers to Selected Exercises

The Answer to the Great Question... Of Life, the Universe and Everything... Is... Forty-two, said Deep Thought, with infinite majesty and calm.

—Douglas Adams, October 1979(from The Hitchhiker’s Guide to theGalaxy, 1979, Pan Books)

Chapter 1

Regular Expressions

1-1. Matching strings

bat, hat, bit, etc.


1-2. First name last

[A-Za-z-]+ [A-Za-z-]+

(Any pair of words separated by a single space, that is, first and last names, hyphens allowed)

1-3. Last name first

[A-Za-z-]+, [A-Za-z]

(Any word and single letter separated by a comma and single space, as in, last name, first initial)

[A-Za-z-]+, [A-Za-z-]+

(Any pair of words separated by a comma and single space, such as, last, first names, hyphens ...

Get Core Python Applications Programming, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.