【问题标题】:Trying to import a string using python in Zapier尝试在 Zapier 中使用 python 导入字符串
【发布时间】:2016-09-22 20:21:42
【问题描述】:

我正在使用带有 python 的 Zapier 代码操作来尝试从以下消息中提取名称:

_id: 57455fc20913b2f400c2671d
actions: []
authorId: 0d0e129c5913b613a49531b9
name: Tiny Meerkat
received: 1464164290.1
role: appUser
source: {u'type': u'web'}
text: Hello

使用此代码:

import re
name = re.search('(?<=name:)(.*?)(?=received)', input['messages'])
return {
    'name': name if name else 'empty'
}

返回的值始终为空。有谁知道为什么?

【问题讨论】:

    标签: python regex zapier


    【解决方案1】:

    你可以用这个

    name = re.search('(?s)(?<=name:)(.*?)(?=received)', x).group(1).strip("\n\r ")
                      <-->                                 <------>
            Allows . to match new line       Returns content of first captured group
    

    您必须使用(?s),因为字符串被分隔在不同的行中。使用(?s). 也匹配新行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-21
      • 2012-04-24
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多