数完后消灭 2 个角色

发布于 2025-01-14 01:54:23 字数 1432 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2025-01-21 01:54:23

如果我正确理解你的问题,你需要的是正则表达式:

import re
example = "gz15gr123da1az4gr1sd23f168zgre4r6z"
re.sub("(\d)gr", r"\1", example)

输出

gz15123da1az41sd23f168zgre4r6z

解释

re.sub 函数采用三个参数:第一个参数是模式,第二个参数是替换,最后一个参数是字符串本身。 (\d)gr 选择包含数字后跟 gr 的部分,然后将其替换为数字 (\d) 本身(删除 gr代码>部分)。

If I understand your question correctly, what you need is regex:

import re
example = "gz15gr123da1az4gr1sd23f168zgre4r6z"
re.sub("(\d)gr", r"\1", example)

Output

gz15123da1az41sd23f168zgre4r6z

Explnatation

The re.sub function takes three arguments: the first argument is a patter, the second one the replacement, and the last of is the string itself. (\d)gr selects the parts that contain a number followed by gr, then replaces it with the number (\d) itself(removing the gr part).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文