Pattern Matching with Regular Expressions
183
Step 4: Join the Matches into a String for the Clipboard
Now that you have the email addresses and phone numbers as a list of strings
in
matches
, you want to put them on the clipboard. The
pyperclip.copy()
func-
tion takes only a single string value, not a list of strings, so you call the
join()
method on
matches
.
To make it easier to see that the program is working, let’s print any
matches you find to the terminal. If no phone numbers or email addresses
were found, the program should tell the user this.
Make your program look like the following:
#! python3
# phoneAndEmail.py - Finds phone numbers and email addresses on the clipboard.
--
snip--
for groups in emailRegex.findall(text):
matches.append(groups[0])
Dostları ilə paylaş: