I am working on a django project to modify database options in the file settings.py.I want to use regular expression to do it. the options just like : 'PASSWORD':'123456', so I have write a function,the code is following:
def config_item(self,data,item,value):
rStr = "'"+item+"':(\s)?'\w*'"
src = "'"+item+"': '"+value+"'"
res = re.sub(rStr,src,data)
return res
So I can call like this to modify password to '000000',
data = config_item(data,'PASSWORD','0000')
But when the source password is blank or dest password is blank ,it does not work.That is ,it does not match 'PASSWORD':'', Are there some wrong with the regular expression. How do I write it rightly.
Maybe try using '[^']*'
instead of '\w*'
I think \w is a bit more strict.