182
Chapter 7
the “dot-com” part (technically known as the
top-level domain), which can
really be dot-anything. This is between two and four characters.
The format for email addresses has a lot of weird rules.
This regular
expression won’t match every possible valid email address, but it’ll match
almost any typical email address you’ll encounter.
Step 3: Find All Matches in the Clipboard Text
Now that you have specified the regular expressions for phone numbers
and email addresses, you can let Python’s
re
module
do the hard work of
finding all the matches on the clipboard. The
pyperclip.paste()
function
will get a string value of the text on the clipboard, and the
findall()
regex
method will return a list of tuples.
Make your program look like the following:
#! python3
# phoneAndEmail.py - Finds phone numbers and email addresses on the clipboard.
import pyperclip, re
phoneRegex = re.compile(r'''(
--
snip--
Dostları ilə paylaş: