相关疑难解决方法(0)

如何编写正则表达式来替换单词但是在Python中保留它的情况?

这甚至可能吗?

基本上,我想将这两个调用sub转换为一个调用:

re.sub(r'\bAword\b', 'Bword', mystring)
re.sub(r'\baword\b', 'bword', mystring)
Run Code Online (Sandbox Code Playgroud)

我真正喜欢的是某种条件替换符号,如:

re.sub(r'\b([Aa])word\b', '(?1=A:B,a:b)word')
Run Code Online (Sandbox Code Playgroud)

我只关心第一个角色的大写.没有其他人.

python regex

6
推荐指数
2
解决办法
887
查看次数

标签 统计

python ×1

regex ×1