Zapier

2016-05-25 17 views
1

私がしようとすると、この次のメッセージから名前を抽出するためのpythonとZapierコードのアクションを使用している中でのpythonを使用して文字列をインポートしようとすると:Zapier

import re 
name = re.search('(?<=name:)(.*?)(?=received)', input['messages']) 
return { 
    'name': name if name else 'empty' 
} 
:このコードを使用して

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

返される値は常に空です。誰にも理由がありますか?

答えて

0

あなたは文字列が異なる行で分離されているので(?s)を使用する必要があり、この

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

を使用することができます。 (?s)を使用すると、.は改行にも一致します。

+0

本当にありがとうございます。 –

関連する問題