为什么python中的findall方法返回元组中电子邮件地址用户名的最后一个字符?

为什么python中的findall方法返回元组中电子邮件地址用户名的最后一个字符?,python,python-3.x,regex,tuples,findall,Python,Python 3.x,Regex,Tuples,Findall,这是复制到我的键盘上的内容: 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|

这是复制到我的键盘上的内容:

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))

因此,当我运行时,我得到的输出是:

Christen E. Alvarez     (972) 786-4438  christenalvarez1@gmail.com
    
Laura Anderson      (940)665-0605   womens-health@sbcglobal.net
    
Alana Andrews       (512) 891-0420  cocosalonaustin@yahoo.com
    
Cynthia Lou Andrews     (572)343-7546   cindy@beautifulsolutionstexas.com
我的问题是,为什么它在emailRegex findall列表中,每个元组中的第二个元素是电子邮件用户名中的最后一个字符吗


另外,如何使phoneRegex findall列表中返回的元组中的第三个元素不是连字符?

仅供参考:您需要学习非捕获组。在这里,
(\w| \.\124;-)+
,您需要一个字符类,
[\w.-]+
,或
(?:\w| \.\124;-)+
基本上每个列表元素都是一个捕获组。如果不希望捕获的输出出现在列表中,请删除括号。删除phone regex中
-?
和电子邮件中
\w | \.-
的括号regex@noah,你对电话regex的评论有效,但当我按照你对email regex所说的做时,它失败了,只输出了电子邮件用户名的第一个字母,即dot,然后是服务提供商、另一个dot和com/org/netsorry,我看得太快了。正如Wiktor所说,要么是
[\w.-]
+,要么是
(?:\w.\.\124;-)+
[('(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')]