I want to deal only with string which is NOT C++
comment, here is the pattern to find out C++
comment:
pattern = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
However, I don't know how to make it to work as my intention.
# Python 3.4.2
s = '''
/****
C++ comments
//pResMgr->CreateDialogEx();
****/
//pResMgr->CreateDialogEx();
/*//pResMgr->CreateDialogEx();*/
// real code, I want to replace only this following line of code
pResMgr->CreateDialogEx();
'''
newS = s.replace('CreateDialogEx', 'Create')
print(newS)
My expected output is:
/****
C++ comments
//pResMgr->CreateDialogEx();
****/
//pResMgr->CreateDialogEx();
/*//pResMgr->CreateDialogEx();*/
// real code, I want to replace only this following line of code
pResMgr->Create();