复制
收藏
提问
全网

老师说:text = "Please contact us at info@example.com or support@sample.org. " \ "For more details, visit https://example.com or call (123) 456-7890." \ "You can also reach us at 987-654-3210. " \ "The event will be held on 2024-08-26, but registration ends by 15/09/2023." 提取邮箱名。电话号码,时间,网址,python代码

机敏织梦师
1个月前
全网
文档
学术
百科
知识库
时间不限
自动

理解问题老师说:text = "Please contact us at info@example.com or support@sample.org. " \ "For more details, visit https://example.com or call (123) 456-7890." \ "You can also reach us at 987-654-3210. " \ "The event will be held on 2024-08-26, but registration ends by 15/09/2023." 提取邮箱名。电话号码,时间,网址,python代码

已完成理解老师说:text = "Please contact us at info@example.com or support@sample.org. " \ "For more details, visit https://example.com or call (123) 456-7890." \ "You can also reach us at 987-654-3210. " \ "The event will be held on 2024-08-26, but registration ends by 15/09/2023." 提取邮箱名。电话号码,时间,网址,python代码

展开阅读网页

import re

text = "Please contact us at info@example.com or support@sample.org. " \
       "For more details, visit https://example.com or call (123) 456-7890." \
       "You can also reach us at 987-654-3210. " \
       "The event will be held on 2024-08-26, but registration ends by 15/09/2023."

# 提取电子邮件
email_regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
emails = re.findall(email_regex, text)

# 提取电话号码
phone_regex = r'(\d{3}|$\d{3}$)[-.\s]?\d{3}[-.\s]?\d{4}'
phones = re.findall(phone_regex, text)

# 提取网址
url_regex = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\$\$,]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
urls = re.findall(url_regex, text)

# 提取日期
date_regex = r'\d{4}-\d{2}-\d{2}|\d{2}/\d{2}/\d{4}'
dates = re.findall(date_regex, text)

print("Emails:", emails)
print("Phones:", phones)
print("URLs:", urls)
print("Dates:", dates)
更专业一些
转笔记
专业
老师说:text = "Please contact us at info@example.com or support@sample.org. " \ "For more details, visit https://example.com or call (123) 456-7890." \ "You can also reach us at 987-654-3210. " \ "The event will be held on 2024-08-26, but registration ends by 15/09/2023." 提取邮箱名。电话号码,时间,网址,python代码
不在提醒

更专业内容正在努力生成中
知识树
老师说:text = "Please contact us at info@example.com or support@sample.org. " \ "For more details, visit https://example.com or call (123) 456-7890." \ "You can also reach us at 987-654-3210. " \ "The event will be held on 2024-08-26, but registration ends by 15/09/2023." 提取邮箱名。电话号码,时间,网址,python代码
如何使用Python进行数据抓取?
Python正则表达式有哪些应用场景?
如何用Python处理文本数据?
在线客服