# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<NewMarket sysname=\"SOCCER(.*?)ODD_EVEN"
test_str = ("<NewMarket sysname=\"SOCCER_CORNERS_FIRST_HALF_DOUBLE_CHANCE\" name=\"1st Half Corners Double Chance\" voidRule=\"false\" settleRule=\"[Period] >= [HT]\">\n"
" <Mappings>\n"
" <OldMarket sysname=\"SOCCER_CORNERS_HALFTIME_DOUBLE_CHANCE\" />\n"
" </Mappings>\n"
" <MarketDefinition captionEn=\"1st Half Corners Double Chance\" captionEl=\"Διπλή Ευκαιρία Κόρνερ Ημιχρόνου\">\n"
" <Odds>\n"
" <Bet code=\"1X\" name=\"HomeDraw\" captionEn=\"{HomeTeam} / Draw\" settleRule=\"[HomeCorners1H] >= [AwayCorners1H]\" />\n"
" <Bet code=\"X2\" name=\"DrawAway\" captionEn=\"{AwayTeam} / Draw\" settleRule=\"[HomeCorners1H] <= [AwayCorners1H]\" />\n"
" <Bet code=\"12\" name=\"HomeAway\" captionEn=\"{HomeTeam} / {AwayTeam}\" settleRule=\"[HomeCorners1H] > [AwayCorners1H] || [HomeCorners1H] < [AwayCorners1H]\" />\n"
" </Odds>\n"
" </MarketDefinition>\n"
" </NewMarket>\n"
" <NewMarket sysname=\"SOCCER_CORNERS_ODD_EVEN\" name=\"Corners Odd/Even\" voidRule=\"false\" settleRule=\"[Period] >= [FT]\">\n"
" <Mappings>\n"
" <OldMarket sysname=\"SOCCER_CORNERS_ODD_EVEN\" />\n"
" </Mappings>\n"
" <MarketDefinition captionEn=\"Match Corners Odd/Even\" captionEl=\"Μονά Ή Ζυγά Κόρνερ Αγώνα\">\n"
" <Odds>\n"
" <Bet code=\"1\" name=\"Odd\" captionEn=\"Odd\" settleRule=\"([TotalCorners] % 2) = 1\" />\n"
" <Bet code=\"0\" name=\"Even\" captionEn=\"Even\" settleRule=\"([TotalCorners] % 2) = 0\" />\n"
" </Odds>\n"
" </MarketDefinition>\n"
" </NewMarket>\n"
" <NewMarket sysname=\"SOCCER_CORNERS_FIRST_HALF_ODD_EVEN\" name=\"1st Half Corners Odd/Even\" voidRule=\"false\" settleRule=\"[Period] >= [HT]\">\n"
" <Mappings>\n"
" <OldMarket sysname=\"SOCCER_CORNERS_FIRST_HALF_ODD_EVEN\" />\n"
" </Mappings>\n"
" <MarketDefinition captionEn=\"1st Half Odd/Even Corners\" captionEl=\"Μονά Ή Ζυγά Κόρνερ 1ου Ημιχρόνου\">\n"
" <Odds>\n"
" <Bet code=\"1\" name=\"Odd\" captionEn=\"Odd\" settleRule=\"([TotalCorners1H] % 2) = 1\" />\n"
" <Bet code=\"0\" name=\"Even\" captionEn=\"Even\" settleRule=\"([TotalCorners1H] % 2) = 0\" />\n"
" </Odds>\n"
" </MarketDefinition>\n"
" </NewMarket>\n"
" <NewMarket sysname=\"SOCCER_CORNERS_SECOND_HALF_ODD_EVEN\" name=\"2nd Half Corners Odd/Even\" voidRule=\"false\" settleRule=\"[Period] >= [FT]\">\n"
" <Mappings>\n"
" <OldMarket sysname=\"SOCCER_CORNERS_SECOND_HALF_ODD_EVEN\" />\n"
" </Mappings>\n"
" <MarketDefinition captionEn=\"2nd Half Odd/Even Corners\" captionEl=\"Μονά Ή Ζυγά Κόρνερ 2ου Ημιχρόνου\">\n"
" <Odds>\n"
" <Bet code=\"1\" name=\"Odd\" captionEn=\"Odd\" settleRule=\"([TotalCorners2H] % 2) = 1\" />\n"
" <Bet code=\"0\" name=\"Even\" captionEn=\"Even\" settleRule=\"([TotalCorners2H] % 2) = 0\" />\n"
" </Odds>\n"
" </MarketDefinition>\n"
" </NewMarket>\n"
" <NewMarket sysname=\"SOCCER_CORNERS_RESULT_NO_DRAW\" name=\"Corners Draw No Bet\" voidRule=\"[Period] >= [FT] && [HomeCorners] = [AwayCorners]\" settleRule=\"[Period] >= [FT] && [HomeCorners] != [AwayCorners]\">\n"
" <Mappings>\n"
" <OldMarket sysname=\"SOCCER_CORNERS_RESULT_NO_DRAW\" />\n"
" </Mappings>\n"
" <MarketDefinition captionEn=\"Match Corners Draw no bet\" captionEl=\"Νικητής Κόρνερ Αγώνα Ισοπαλία ΄Οχι Στοίχημα\">\n"
" <Odds>\n"
" <Bet code=\"1\" name=\"Home\" captionEn=\"{HomeTeam}\" settleRule=\"[HomeCorners] > [AwayCorners]\" />\n"
" <Bet code=\"2\" name=\"Away\" captionEn=\"{AwayTeam}\" settleRule=\"[HomeCorners] < [AwayCorners]\" />\n"
" </Odds>\n"
" </MarketDefinition>\n"
" </NewMarket>")
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