As you have already found out, regex can do the job pretty easily:
import re
filedata="minRequiredPasswordLength="9""
r="11"
result = re.sub(r'minRequiredPasswordLength="\d*"', r'minRequiredPasswordLength="{}"'.format(r), filedata)
print(result)
>>>> minRequiredPasswordLength="11"
0
solved Python – trying to replace a text string that contains “”