Книга: Automate the Boring Stuff with Python: Practical Programming for Total Beginners
Назад: II. Automating Tasks
Дальше: 8. Reading and Writing Files

]

In this chapter, you’ll start by writing a program to find text patterns without using regular expressions and then see how to use regular expressions to make the code much less bloated. I’ll show you basic matching with regular expressions and then move on to some more powerful features, such as string substitution and creating your own character classes. Finally, at the end of the chapter, you’ll write a program that can automatically extract phone numbers and email addresses from a block of text.

.

.

.

for more information. You can also pass other options for the second argument; they’re uncommon, but you can read more about them in the resources, too.

, press CTRL-A to select all the text on the page, and press CTRL-C to copy it to the clipboard. When you run this program, the output will look something like this:

. The tutorial website is also a useful resource.

Now that you have expertise manipulating and matching strings, it’s time to dive into how to read from and write to files on your computer’s hard drive.

] Cory Doctorow, “Here’s what ICT should really teach kids: how to do regular expressions,” Guardian, December 4, 2012, .

© RuTLib.com 2015-2018