# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"RC[0-9]{6}.[0-9]{4}.[A-Za-z]{1}[0-9]{5}|MP[0-9]{6}.[0-9]{4}.[A-Za-z]{1}[0-9]{5}|CO[0-9]{6}.[0-9]{4}.[A-Za-z]{1}[0-9]{5}"
test_str = ("Rechargement reussi. Montant de la transaction : 80 FCFA, ID transaction : RC220514.2328.A31840, Frais : 0 FCFA, Commission : 0 FCFA, Nouveau Solde : 0.28FCFA Other msisdn 658747305.\n\n"
"Paiement de FORFAIT INTERNET en succes par 658747305. \n"
"ID transaction: MP220512.2119.C83780, Montant: 250 FCFA. \n"
"Nouveau solde: 80.28 FCFA.\n\n"
"Retrait d'argent reussi par le 693734202 avec le Code : 226752. Informations detaillees : Montant: 2000 FCFA, Frais: 50 FCFA, No de transaction CO220428.2045.B63327, montant net debite 2050 FCFA, Nouveau solde: 387.1 FCFA.\n\n"
"CashOut success by 698039077 with the Code : 375533. Detailed information : Amount: 1500 FCFA, Fees: 45 FCFA, Transaction ID: CO211211.1932.C52092, Net amount debited 1545FCFA, New balance: 315.1 FCFA.")
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