# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"Date:\n(.*)\n\nNumber"
test_str = ("Voice Mail Message: Double click on the attachment to play the voice mail file.\n\n"
"Date:\n"
"12/01/2014 01:28:36 PM\n\n"
"Number:\n"
"800-123-4567, JOHN SMITH\n\n"
"CallerID:\n"
"123-456-7890, JANE DOE\n\n"
"Destination:\n"
"Voice Mail\n\n"
"File Duration:\n"
"00:00:37\n\n"
"======================\n\n"
"Name : Jane Doe\n\n"
"Address : 123 Fake Street , Miami , Florida \n\n"
"Phone : 123-456-7890\n\n"
"Ye, my name is Jane Doe. I own the property at 123 Fake Street , Miami , Florida. You sent me a couple of postcards. Let me know if you're interested in making an offer. it's a single family home.3 bedrooms, 2 baths. Has a single efficiency in the back, that's an additional rental income.\n\n"
"Again, Jane Doe and that's 123 Fake Street and my phone number is 123-456-7890. Thanks !\n")
matches = re.search(regex, test_str, re.IGNORECASE | re.DOTALL | re.MULTILINE)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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