# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"([A-Z,0-9, ]*\d )?(?:(\d\d)(\d\d)/)?([a-z,A-Z,0-9, ,\-,',_,\.,\/ ,\*]*?)( [\-\+]?\d+,\d\d)?"
test_str = ("CARTE X1796 1209/FREE MOBILE 75 PARIS\n"
"CARTE 51002 ITUNES.COM/BILL LUXEMBURG\n"
"CARTE X1796 0209/SNCF INTERNET 75 PARIS CEDEX 09\n"
"CARTE X1796 1408/THE COLUMBIA STO 124 -156,76\n"
"CARTE X1796 1208/NICKLAUS NORTH G 124 -168,41\n"
"CARTE 51002 PAYPAL*DIGITALRIVE DRI* 35314369001\n"
"CARTE 51002 APPLE ONLINE EURO HOLLYHILL\n"
"PAYPAL*PAYPAL*PHIBUELEC 4029357733\n"
"PAYPAL*OSCARO COM 35314369001\n")
subst = "Nom rationnalisé: $4\\rMoyen de paiement: $1\\rDate opération :$2/$3\\r\\r"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0)
if result:
print (result)
# 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