# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^msgid \"\"\r?\n([\s\S]*?)\r?\n(?=^msgstr \"\"\r?\n?)"
test_str = ("#: apps/catalogue/abstract_models.py:206\n"
"msgid \"\"\n"
"\"Universal Product Code (UPC) is an identifier for a product which is not \"\n"
"\"specific to a particular supplier. Eg an ISBN for a book.\"\n"
"msgstr \"\"\n\n"
"#: apps/catalogue/abstract_models.py:213\n"
"#: templates/oscar/dashboard/catalogue/product_list.html:87\n"
"#: templates/oscar/dashboard/catalogue/product_update.html:168\n"
"#: templates/oscar/dashboard/catalogue/product_update.html:190\n"
"msgid \"Parent\"\n"
"msgstr \"والد\"\n\n"
"#: apps/catalogue/abstract_models.py:214\n"
"msgid \"\"\n"
"\"Only choose a parent product if this is a 'variant' of a canonical \"\n"
"\"catalogue. For example if this is a size 4 of a particular t-shirt. Leave \"\n"
"\"blank if this is a CANONICAL PRODUCT (ie there is only one version of this \"\n"
"\"product).\"\n"
"msgstr \"\"")
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