-1

I am new in regular expression. I want to remove a uppercase letter if it has lowercase before and after it. If the input is "I wilYl go theXre" then the output should be "I will go there". How can I get it?

Sajib
  • 19
  • 3

1 Answers1

1

You can use a lookaround:

import re 

s='I wilYl go theXre'

print(re.sub(r'(?<=[a-z])([A-Z])(?=[a-z])','',s))
#               ^ lookbehind     ^lookahead

Prints:

I will go there
dawg
  • 98,345
  • 23
  • 131
  • 206