我需要删除'
和'
之间的所有字符,而忽略命令\n
string="Hello my name is 'bla bla bla\n what do you need? \n nothing!' See you bye bye."
我尝试了以下命令,但没有成功:
string = re.sub(r"'.*?'", "", string, flags=re.MULTILINE)
预期输出:
"Hello my name is See you bye bye."
答案 0 :(得分:0)
您可以使用re.DOTALL
标志使.
匹配换行符:
string = re.sub(r"'.*?'", "", string, flags=re.DOTALL)