# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"0\R+(.+)\R(?:(?!CDN)(?!^0$)[\s\S])+(?:\RCDN\$\h+(\d+\.\d+))?(?:\RCDN\$\h+(\d+\.\d+))?\R(?:(?!^0$)[\s\S])+"
test_str = ("\n"
"0\n\n"
"South Park™: The Stick of Truth™\n"
"OVERALL REVIEWS:\n"
"OVERWHELMINGLY POSITIVE\n"
"RELEASE DATE:\n"
"3 MAR, 2014\n"
"-75%\n"
"CDN$ 39.99\n"
"CDN$ 9.99\n"
"Add to Cart\n"
"RPGComedyAdventureFunnyTurn-Based\n"
"Added on 8/9/2020 ( remove )\n\n"
"0\n\n"
"Grand Theft Auto V\n"
"OVERALL REVIEWS:\n"
"VERY POSITIVE\n"
"RELEASE DATE:\n"
"13 APR, 2015\n"
"View Details\n"
"Open WorldActionMultiplayerAutomobile SimCrime\n"
"Added on 1/15/2020 ( remove )\n\n"
"0\n\n"
"System Shock\n"
"OVERALL REVIEWS:\n"
"NO USER REVIEWS\n"
"RELEASE DATE:\n"
"SUMMER 2021\n"
"CDN$ 51.49\n"
"Add to Cart\n"
"ActionAdventureCyberpunkSci-fiImmersive Sim\n"
"Added on 6/9/2020 ( remove )\n")
subst = "$1 $2 $3\\n"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
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