You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从transaction_obj["group"]的输出中提取目标字符串值?

解决提取Transaction值的问题

从你给出的输出Transaction: 83a9bb1f808c464fbf21952abbfd8c0a来看,transaction_obj["group"]是字符串类型,不是字典或列表,所以你之前用索引的方式无效。

可以用以下几种方法提取目标值:

  • 分割字符串法:按冒号加空格分割,取第二部分:

    transaction_id = transaction_obj["group"].split(": ")[1]
    print(transaction_id)
    
  • 正则表达式匹配:匹配固定格式的32位十六进制UUID:

    import re
    match = re.search(r'[0-9a-f]{32}', transaction_obj["group"])
    if match:
        print(match.group())
    
  • 固定长度切片:如果前缀Transaction: 长度固定(共13个字符),直接截取后续内容:

    transaction_id = transaction_obj["group"][13:]
    print(transaction_id)
    

内容的提问来源于stack exchange,提问作者Milind Sahu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 09:05:24