英文python 代码怎么输出

We have some email addresses in the format: *"username@universityname.edu.countrycode"* e.g. "steve@rmit.edu.au"

User names, university names and country codes are composed of letters only.

Write a program to print the user name, the university name and the country code of a given email address on seperate lines.

Example: If the email address is: steve@rmit.edu.au, then, the following should be printed:

steve

rmit

au

Hint:

  • Lab Task 3.5 - Regular Expressions

 

 

# Regex explanation

# ^         # Match the start of the line
# \d+       # Match one or more digits
# (\d+)     # Use the round brackets to extract the digits as a group
# \s+       # Match one or more spaces
# [\w+]     # Match one or more word-characters
# ([\w+])   # Use the round brackets to extract a single word as a group
# [\w\s]+   # Match one or more words (with spaces in between)
# ([\w\s]+) # Use the round brackets to extract more than one word as a group
# $         # Match the end of the line


# Write your code below this line
 

import re

s='steve@rmit.edu.au'

for x in re.findall(r'(.*)@(.*)\.(.*)\.(.*)',s):

    for y in x:

        print(y)

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632