# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"[2][0-9][0-9][0-9]\/[0-9][[0-9]\/"
test_str = ("161 1 2015/12/17 14:52:08:44648 13668 38528 1 *** 15 5 CDF_ENTRY [Id=1] hook_MFCreateSourceResolver: Entering. \n"
"162 1 2015/12/17 14:52:08:44664 13668 38528 1 *** 15 5 CDF_ENTRY [Id=2] SourceResolverWrapper::FinalConstruct: Entering. \n"
"163 1 2015/12/17 14:52:08:44664 13668 38528 1 *** 20 5 CDF_ENTRY [Id=2] SourceResolverWrapper::FinalConstruct: Leaving. (hr=0x0) \n"
"164 1 2015/12/17 14:52:08:44665 13668 38528 1 *** 20 5 CDF_ENTRY [Id=1] hook_MFCreateSourceResolver: Leaving. (hr=0x0) \n"
"165 1 2015/12/17 14:52:08:44666 13668 38528 1 *** 15 5 CDF_ENTRY [Id=2] SourceResolverWrapper::BeginCreateObjectFromURL: Entering. ")
subst = "2016/01/"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 1, re.IGNORECASE)
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