我正在尝试使用正则表达式从一串文本中获取电子邮件地址。
如何让我的简单代码仅提取电子邮件地址而不是整行?
demo_text = """hsds hjdsjd ksdkj
Reason: 550 abc@gmail.com... No such user
sdhjsdjh
"""
# the following code extracts the whole line "Reason: 550 abc@gmail.com... No such user"
# how do I just extract "abc@gmail.com"?
email = re.search("Reason: 550 (.+)... No such user", demo_text).group(0)