0

I have the text "languageType" : "en", and I want to replace it with en. How do I do it using replace? I've tried this so far so it's not working

lang = s.split(":")[0].replace("[\"']", "", -1).strip()
print(lang)

But I keep getting "en"

1 Answers1

1

The replace method doesn't accept a regular expression, but rather a string. To replace with a regex use re.sub(). See How to input a regex in string.replace?

I've made the same mistake before, myself.

xdhmoore
  • 8,935
  • 11
  • 47
  • 90