Why is the findall method in my python returning the last character of my email address username in the tuple?

164 Views Asked by At
import pyperclip
import re
searchItems=pyperclip.paste()
phoneRegex= re.compile(r"(\(\d\d\d\))?\s?(\d\d\d)(-?)(\d\d\d\d)")
print(phoneRegex.findall(searchItems))
emailRegex= re.compile(r"((\w|\.|-)+)(@)(\w+)(\.)(com|org|gov|net)")
print(emailRegex.findall(searchItems))

This is what is copied to my keyboard:

Christen E. Alvarez     (972) 786-4438  [email protected]
    
Laura Anderson      (940)665-0605   [email protected]
    
Alana Andrews       (512) 891-0420  [email protected]
    
Cynthia Lou Andrews     (572)343-7546   [email protected]

So when I run, the output I get is:

[('(972)', '786', '-', '4438'), ('(940)', '665', '-', '0605'), ('(512)', '891', '-', '0420'), ('(572)', '343', '-', '7546')]
[('christenalvarez1', '1', '@', 'gmail', '.', 'com'), ('womens-health', 'h', '@', 'sbcglobal', '.', 'net'), ('cocosalonaustin', 'n', '@', 'yahoo', '.', 'com'), ('cindy', 'y', '@', 'beautifulsolutionstexas', '.', 'com')]

The question I have is, why is it in the emailRegex findall list, is the second element in each tuple the last character in the email username?

Also, how do I make it that in the phoneRegex findall list, that the third element in the tuples returned isnt a hyphen?

0

There are 0 best solutions below