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 live online training, plus books, videos, and digital content from nearly 200 publishers.