import re
regex = re.compile(r"Date_Number\(.*\)")
test_str = ("WEEK = '2'\n"
"Date_Number(3,4,5,6,7,8)\n"
"AND\n"
"Allowance='100'\n"
"AND\n"
"((End_Date<'2017-09-17 00:00:00'\n"
"AND\n\n"
"Saturday_Name)")
subst = "Date_Number(22,25,27,28,29)"
result = regex.sub(subst, test_str, count=1)
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