1

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?

2
  • Have you looked at string functions? Have you tried using replace() ? Commented Nov 23, 2017 at 23:15
  • Yes! I looked further and I was using it in the wrong way! Thanks! Commented Nov 23, 2017 at 23:24

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Why re.sub when you could just use str.replace?
Both work fine. str.replace is likely more fitting, though. I just though of re.sub first and it worked.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.