2 回答
TA贡献1835条经验 获得超7个赞
试试这个:
import re
limits = ['limit=5e8f0dc0-4074-481d-a12c-5d3a70406ad7&location=d877f1f9-fae3-4f39-82ca-499ec8a7a0d2', 'location=d877f1f9-fae3-4f39-82ca-499ec8a7a0d2', 'sourceLimitAllocationOid=212a7e22-aafd-40e3-9684-621dae6708af&sourceUnits=5000&sourceUnitOfMeasureCode=TON&tragetUnitOfMeasureOid=1bec1009-90d3-de11-9251-001d092afdd0&targetLimitCommodityOid=7e7a1112-b7c7-4563-9bd4-702e14b139f4', '', 'limit=5e8f0dc0-4074-481d-a12c-5d3a70406ad7&location=2e12899b-e84d-4b1a-8b89-faced0771efc', '', 'location=2e12899b-e84d-4b1a-8b89-faced0771efc', 'sourceLimitAllocationOid=bfa24508-a4e3-4138-8d29-7e9b7c1ea559&sourceUnits=3000000&sourceUnitOfMeasureCode=BU&tragetUnitOfMeasureOid=1bec1009-90d3-de11-9251-001d092afdd0&targetLimitCommodityOid=7e7a1112-b7c7-4563-9bd4-702e14b139f4', '', '', 'limit=c0ba884c-800b-4174-8374-0bc5515f8282&location=b3d785e6-4d0c-460b-8e2c-1f32732a1a20', 'location=b3d785e6-4d0c-460b-8e2c-1f32732a1a20']
for el in limits:
a = re.search(r'\b(limit)\b', el)
if a is not None:
ind = a.start()
print(el[ind+5:ind+38])
TA贡献1852条经验 获得超7个赞
根据本教程,您可以执行以下操作:
offset = len("limit")
limit = ""
for item in limits:
index = item.find("limit")
if (index != -1):
limit = item[ (limit + offset + 1): (limit + offset + 34) ]
break
除了您要求的内容之外,这里还有一些事情要做。首先,我假设里面只有一个字符串limit。如果不是,请删除该break语句并将limit赋值更改为append. 其次,我假设您不想=从字符串中取出 ,所以我实际上是在开始和结束处添加一个来做到这一点。或者,如果这是您想要做的,您可以稍后删除第一个字符。
添加回答
举报