# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r".*@softcomputer\.com>? *(?:\"? *<\S+>)?$"
test_str = ("== Real scc\n"
"Mary Bills <marybil@softcomputer.com>\n"
" <ellie@softcomputer.com>\n"
" <thereasaw@softcomputer.com>\n"
"test@softcomputer.com\n"
"<test@softcomputer.com>\n"
"olexiyry@softcomputer.com <olexiyry@softcomputer.com>\n"
"Deseriee Harkins <deseriee@softcomputer.com>\n\n"
"== Forged scc\n"
"Dorota Mazurek <dorotam@softcomputer.com> <reservations@nesthotel.com>\n"
"Nikki Taft <nicolet@softcomputer.com> <Muhammad.owais@abtach.com>\n"
"Lynette Didia <ldidia@softcomputer.com> <Muhammad.owais@abtach.com>\n"
"Dorota Mazurek <dorotam@softcomputer.com> <centralbookings@kbcsa.co.za>\n"
"Jeffrey Marr <jeffreym@softcomputer.com> <srvadv5.blr@vw-ppsmotors.co.in>\n"
"Iryna Dmytriyeva @SCC <idmy@softcomputer.com> <sc@grupoinrexsa.com>\n"
"Vickie Nix vickieh@softcomputer.com <m.recovery@albarondebt.com>\n"
"Bill Young <billyo@softcomputer.com> <sara@eaurenaissance.com>\n\n"
"== Questionable\n"
"\"Kurt Veith <kurtv@softcomputer.com>\" <marlene.robles@mld.com.mx>\n"
"\"softcomputer.com\" <MAIL.QUOTA@servers.com>\n"
"\"marksm@softcomputer.com\" <mark560sl@gmail.com>\n\n"
"== Valid non-forged addresses\n"
"\"sarahze@softcomputer.com via Smartsheet\" <user@smartsheet.com>\n"
"\"yuvi softcomputer.com\" <hugginshospital.notification@zixmessagecenter.com>\n"
"<technicalsupport@softcomputer.com.au>\n"
"\"Secure Email From yevgeny@softcomputer.com via Message Pickup Center\" <emx-intermedia@securemail.intermedia.net>\n"
"\"Secure Email From yevgeny@softcomputer.com via Message Pickup Center\" <emx-intermedia@securemail.intermedia.net>\n"
"\"mpettis@softcomputer.com via SurveyMonkey\" <member@surveymonkeyuser.com>")
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