在re.sub命令python上忽略“ \ n”

时间:2019-03-13 17:54:35

标签: python string

我需要删除''之间的所有字符,而忽略命令\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."

1 个答案:

答案 0 :(得分:0)

您可以使用re.DOTALL标志使.匹配换行符:

string = re.sub(r"'.*?'", "", string, flags=re.DOTALL)