gpt4 book ai didi

python - 在python中的两个引号之间添加文本

转载 作者:行者123 更新时间:2023-11-28 19:52:53 25 4
gpt4 key购买 nike

我不擅长正则表达式,请原谅我问这个问题我有这样的字符串:

4H71NP35P2",""
80844UNWR2",""
53UT5Z7E09",""
963ZF761A4",""
9U30538OX8",""
F1CK67N510",""
308VWHR688",""
6I5E8XKL6H",""
Y42WHYY997",""
3SF73CDEGX",""
JGQB0X133N",""
5Y5Z956O45",""
XKMXJJA822",""
Y0ZO3N28O1",""
2F59677ZX7",""
77T513NIC9",""
RH799SKGN7",""

我想在“”之间添加一个字符串,我尝试了一些正则表达式代码,但没有一个有效。

结果我想要类似的东西

4H71NP35P2","somthing1"
80844UNWR2","somthing2"
53UT5Z7E09","somthing3"
.
.
.

谢谢。

最佳答案

给定大字符串,你可以使用正则表达式:

import re
s = """
4H71NP35P2",""
80844UNWR2",""
53UT5Z7E09",""
963ZF761A4",""
9U30538OX8",""
F1CK67N510",""
308VWHR688",""
6I5E8XKL6H",""
Y42WHYY997",""
3SF73CDEGX",""
JGQB0X133N",""
5Y5Z956O45",""
XKMXJJA822",""
Y0ZO3N28O1",""
2F59677ZX7",""
77T513NIC9",""
RH799SKGN7",""
"""
new_s = re.sub('""', '{}', s).format(*['"something{}"'.format(i) for i, a in enumerate(re.findall('""', s), start=1)])

输出:

4H71NP35P2","something1"
80844UNWR2","something2"
53UT5Z7E09","something3"
963ZF761A4","something4"
9U30538OX8","something5"
F1CK67N510","something6"
308VWHR688","something7"
6I5E8XKL6H","something8"
Y42WHYY997","something9"
3SF73CDEGX","something10"
JGQB0X133N","something11"
5Y5Z956O45","something12"
XKMXJJA822","something13"
Y0ZO3N28O1","something14"
2F59677ZX7","something15"
77T513NIC9","something16"
RH799SKGN7","something17"

关于python - 在python中的两个引号之间添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49135476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com