Search code examples
pythonpython-3.xreplacetranslatestrip

Deletion of multiple characters inside of a string


i want the string 'abc'

abc="['one']"\n['two']"

to output

one 
two 

as far as i know:

.strip() only replaces characters at the beginning and at the ending of the string

.translate() only takes one variable

.replace() only works with 1 character.


Solution

  • You can use re.

    import re
    abc = re.sub(r"['\[\]]", '', abc)
    

    worked for me.