我有一些示例字符串.如何用较长的字符串替换较长字符串中第一次出现的字符串?
regex = re.compile('text')
match = regex.match(url)
if match:
url = url.replace(regex, '')
Run Code Online (Sandbox Code Playgroud) 给定字符串为:
s = "Python is programming language"
Run Code Online (Sandbox Code Playgroud)
在此,我想用任何字符替换第二次出现的'n',比方说'o'。预期的字符串将是:
"Python is programmiog language"
Run Code Online (Sandbox Code Playgroud)
如何在 python 中做到这一点?replace我可以只使用函数来完成吗?或任何其他方式来做到这一点?