Deleting specific control characters(\n \r \t) from a string

后端 未结 6 1257
鱼传尺愫
鱼传尺愫 2021-02-20 11:36

I have quite large amount of text which include control charachters like \\n \\t and \\r. I need to replace them with a simple space--> \" \". What is the fastest way to do this

6条回答
  •  暖寄归人
    2021-02-20 11:57

    my_string is the string where you want to delete specific control characters. As strings are immutable in python, after substitute operation you need to assign it to another string or reassign it:

    my_string = re.sub(r'[\n\r\t]*', '', my_string)
    

提交回复
热议问题