使用 python 在 Zapier 中的字符串中的字符之间提取数据
Extract data in between characters within string in Zapier using python
我正在努力从文本字符串中提取用户的 Twitter 句柄。
文本始终采用这种格式:
SomeText (@handle)
顺便说一句,我 运行 这是多步骤 zap 中的一个步骤。
我的想法是使用 python 使用以下代码提取括号之间的所有内容:
s = input_data['s']
return s[s.find("(")+1:s.find(")")]
我根据文档在我的 zap 中定义了 s,请参见屏幕截图:
我收到以下错误:
'str'对象没有属性'copy'
使用正则表达式,如:
import re
text1 = "SomeText (@handle)"
text2 = "1 (bla bla) article #author: #something (@handle)"
res = re.search(r"\(([^)]*)\)$", text2)
res.groups()[0]
text1 和 text2 的结果都是“@handle”。
您的问题是从 Python 代码步骤返回的数据必须 JSON 可序列化。
试试这个:
s = input_data['s']
return {'handle': s[s.find("(")+1:s.find(")")]}
我正在努力从文本字符串中提取用户的 Twitter 句柄。
文本始终采用这种格式:
SomeText (@handle)
顺便说一句,我 运行 这是多步骤 zap 中的一个步骤。 我的想法是使用 python 使用以下代码提取括号之间的所有内容:
s = input_data['s']
return s[s.find("(")+1:s.find(")")]
我根据文档在我的 zap 中定义了 s,请参见屏幕截图:
我收到以下错误:
'str'对象没有属性'copy'
使用正则表达式,如:
import re
text1 = "SomeText (@handle)"
text2 = "1 (bla bla) article #author: #something (@handle)"
res = re.search(r"\(([^)]*)\)$", text2)
res.groups()[0]
text1 和 text2 的结果都是“@handle”。
您的问题是从 Python 代码步骤返回的数据必须 JSON 可序列化。
试试这个:
s = input_data['s']
return {'handle': s[s.find("(")+1:s.find(")")]}