Carlos Macedo
Carlos Macedo

Reputation: 13

How to remove the "quotation marks" inside a string in python?

I have a string similar to this "A["B"]C" I need this string to look like "A[B]C". Do you know how to do it?

Upvotes: 1

Views: 2105

Answers (1)

Jemi Salo
Jemi Salo

Reputation: 3751

You can use re.sub for this.

import re

string = "[6->['A', 'B']; 7->['ABC']]"
string = re.sub("'","",string)

That will remove all ' characters from the string.

To get rid of " as well:

string = re.sub("['\"]","",string)

Upvotes: 1

Related Questions