如果前一个字母和下一个字母为小写字母,则使用正则表达式删除大写字母吗?

问题描述 投票:0回答:1

我是新来的正则表达式。我想删除一个大写字母,如果它之前和之后都有小写字母。如果输入为"I wilYl go theXre",则输出应为"I will go there"。我如何得到它?

python regex string uppercase lowercase
1个回答
1
投票

您可以使用环顾四周:

import re 

s='I wilYl go theXre'

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

打印:

I will go there
© www.soinside.com 2019 - 2024. All rights reserved.