6. Regular Expressions, Part I

Increasingly, the most sophisticated computer software deals with patterns— for example, speech patterns and the recognition of images. This chapter deals with the former: how to recognize patterns of words and characters. Although you can’t construct a human language translator with these techniques alone, they are a start.

That’s what regular expressions are for. A regular expression is a pattern you specify, using special characters to represent combinations of specified characters, digits, and words. It amounts to learning a new language, but it’s a relatively simple one, and once you learn it, this technology lets you to do a great deal in a small space—sometimes only a statement or two—that would otherwise ...

Get Supercharged Python: Take Your Code to the Next Level, First 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.