# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\b[a-z.]+@[a-z]+\.[a-z]+"
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 = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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