import re
regex = re.compile(r"\b[a-z.]+@[a-z]+\.[a-z]+", flags=re.MULTILINE)
test_str = ("Practice @Geeksforgeeksexpand_more\n"
"Algorithmsexpand_more\n"
"Data Structuresexpand_more\n"
"Programming Languagesexpand_more\n"
"Web Technologiesexpand_more\n"
"Tutorial Libraryexpand_more\n"
"Computer Science Subjectsexpand_more\n"
"GATE 2021expand_more\n"
"UGC NET / ISROexpand_more\n"
"QUIZ Sectionexpand_more\n"
"Puzzles\n"
"Geeksforgeeks Initiativesexpand_more\n"
"Contact Us\n"
"Address:\n"
"GeeksforGeeks\n"
"5th & 6th Floor, Royal Kapsons, A- 118,\n"
"Sector- 136, Noida, Uttar Pradesh (201305)\n\n"
"For feedback and queries: feedback@geeksforgeeks.org\n\n"
"For course related queries: geeks.classes@geeksforgeeks.org\n"
"For payment related issues: geeks.classes@geeksforgeeks.org\n"
"For any issue in a purchased course : complaints@geeksforgeeks.org\n"
"To contribute, please see the contribute \n\n"
"page")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html