# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"TTRR:\s*\K\d+(?:\.\d+)?(?=\.)"
test_str = "Using Notifications API: Strategy ON_TARGET:LookForward Ratio: 0.25 Num of hours back: 6 Rpr Cfg--> FP: 9.02 CP: 18.04 MSR: 0.51 MPR: 0.49 TTRR: 0.51. RepricingMethod_ReachTopRankOnTarget: Sampling info: Dilutions: 2_1_1_7_4_2-AKQSGIBQINE7B, 1_1_1_3_4_2-A2TBTG410J2ORU, 1_1_1_5_4_2-AQNACJEM8PUJ1, 1_1_1_6_4_2-A2R0FX412W1BDT, 1_1_1_6_4_2-A1TFBK3C7LO58P, 1_1_1_4_4_2-A1WMYU489BEYM4, 1_1_1_7_3_2-A3G2RBEZBLAJ53, 1_1_1_5_4_2-A2RFSIF56F6W5J, 1_1_1_6_4_2-AAL7E530K3IX2, 1_1_1_7_4_2-AFAGM2K2OIRAD, 1_1_1_6_4_2-APRB74G8QOR1X, 1_1_1_5_3_2-A24POLY6RKLSW7, 1_1_1_5_4_2-A18IJX3G7FD5MC, 1_1_1_5_3_2-A1UEW3GW612BDQ, 1_1_1_7_4_2-A2G88111572J8M, 1_1_1_4_4_2-A2IKHPELK48TV7, 1_1_1_7_4_2-A79CLRHOQ3NF4, Additions: None.New TTR: 0.9 Merchant is not top ranked, merchant group known (2_1_1_7_4_2-AKQSGIBQINE7B), top ranked group known (2_1_1_7_4_2-ATVPDKIKX0DER), taking prices of 1 groups above/equal merchant group as reference. Lowest landing price within these groups is 9.19 . Initially suggested change: 0.0, change determined upon historical analysis: 0.0 with significance of 1.0, prediction for top rank: false, state trace: -_S6_S8- HWP: null- LLP: 9.02 Reducing price obtained by history to 8.91. Modification: New price lower than floor price, reset to floor price. Target optimization: Current top rank ratio is 0.0, different optimal ratio was not found."
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