จงเขียนโปรแกรมภาษา Python เพื่อค้นหาและสกัดข้อมูล email address จากไฟล์ข้อความที่มีหลายบรรทัด โดยใช้ Regular Expression
คำแนะนำ:
re ของ Python[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}ไฟล์ sample_text.txt:
สวัสดีครับ ผมชื่อสมชาย
Email: somchai.test@example.com
โทร: 081-234-5678
ติดต่อทีมงานได้ที่:
- ฝ่ายขาย: sales@company.co.th
- ฝ่ายสนับสนุน: support@company.co.th
- CEO: ceo.admin@company.com
สำหรับข้อมูลเพิ่มเติมติดต่อ:
john.doe123@gmail.com หรือ jane_smith@university.ac.th
Email ที่ไม่ถูกต้อง: invalid@, @invalid.com, test@.com
กำลังค้นหา email จากไฟล์: sample_text.txt
============================================================
พบ email ทั้งหมด 6 รายการ:
✓ บรรทัดที่ 2: somchai.test@example.com
✓ บรรทัดที่ 6: sales@company.co.th
✓ บรรทัดที่ 7: support@company.co.th
✓ บรรทัดที่ 8: ceo.admin@company.com
✓ บรรทัดที่ 11: john.doe123@gmail.com
✓ บรรทัดที่ 11: jane_smith@university.ac.th
============================================================
Email ที่ไม่ซ้ำกัน (6 รายการ):
- ceo.admin@company.com
- jane_smith@university.ac.th
- john.doe123@gmail.com
- sales@company.co.th
- somchai.test@example.com
- support@company.co.th
============================================================
สถิติ Domain:
- company.co.th: 2 email(s)
- example.com: 1 email(s)
- company.com: 1 email(s)
- gmail.com: 1 email(s)
- university.ac.th: 1 email(s)