2021年3月20日星期六

How to replace value within a bracket in python

Given string = "a(a123-bcd-a456)ppll"

Goal: replace the "a" that are within the bracket with "A"

Desire output = "a(A123-bcd-A456)ppll"

I have tried:

regex = '\(.*?\)'  re.sub(regex, string, string.replace("a", "A"))  

but it results in Aa(a123-bcd-a456)ppllppll?

https://stackoverflow.com/questions/66729021/how-to-replace-value-within-a-bracket-in-python March 21, 2021 at 01:03PM

没有评论:

发表评论