相关疑难解决方法(0)

在Python中替换第一次出现的字符串

我有一些示例字符串.如何用较长的字符串替换较长字符串中第一次出现的字符串?

regex = re.compile('text')
match = regex.match(url)
if match:
    url = url.replace(regex, '')
Run Code Online (Sandbox Code Playgroud)

python regex

98
推荐指数
2
解决办法
8万
查看次数

如何替换字符串中第一次出现的字符?

给定字符串为:

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我可以只使用函数来完成吗?或任何其他方式来做到这一点?

python string

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×2

regex ×1

string ×1