import re
regex = re.compile(r"(.*?'hello'.*?),'hello',(.*)")
test_str = ("'one',2,'three','hello','xyz',5,'hello','mnr','hello','axi'\n"
"'onae',2,'tree','hello','xyz',6,'hello','mnr','hello','asd'\n"
"'onee',2,'xdsa','hello','xyz',5,'hello','mnr','hello','aew'\n"
"'owne',2,'thr','hello','xyz',3,'hello','mnr','hello','az'\n"
"'ocne',2,'tee','hello','xyz',5,'hello','mnr','hello','zse'\n"
"'owne',2,'tre','hello','xyz',2,'hello','mnr','hello','aai'")
subst = "$1,0,$2"
result = regex.sub(subst, test_str)
if result:
print(result)
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