Xem lý thuyết RegEx
ở đây
Xem format email ở đây
Ví dụ Extract Email:
Code:
'''
Yêu cầu:
Dùng RegEx để lấy ra tất cả các địa chỉ email từ chuỗi txt (kết quả đưa vào list)
'''
import re
txt = 'Hello from shubhamg+199630@gmail.com to pri.ya@yahoo.co.kr,pr_iya@yahoo.com,priya@yahoo to-ny@yahoo.com.vn about the meeting @2PM'
#regex ="[a-zA-Z0-9!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+"
regex ="[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+"
email = re.findall(regex, txt)
print(email)
Kết quả:
C:\python>python Demo.py
['shubhamg+199630@gmail.com', 'pri.ya@yahoo.co.kr', 'pr_iya@yahoo.com',
(...)
Học Python Qua Ví Dụ #018 - Regular Expression Trong Python
1. Regular Expression (RegEx) Funtions:
Match: Trả về kết quả THÀNH CÔNG hoặc None với mẫu trong chuỗi có
cờ tùy chọn
Search: Trả về kết quả THÀNH CÔNG nếu tìm thấy hoặc None nếu không
tìm thấy
(...)
Học Python Qua Ví Dụ #017 Bài Tập - Convert Dictionary To List Trong Python
Học Python Qua Ví Dụ #016 - Dictionary Trong Python
Windows, Remote Desktop Protocol (RDP) - Do Not Allow Drive/Clipboard Redirection Policies
Windows, Remote Desktop Protocol (RDP) - Do Not Allow Drive/Clipboard Redirection Policies
Subscribe to:
Posts (Atom)