I'm trying to extract some values from discord message in Zapier.
The content of the message should look somewhat like this (almost like YAML):
channel: <#1234567890123456789>
as: Bot nicname
image: http://example.com/
content:
Hello, world!
Where image
and as
fields are optional.
I have created 2 regular expressions to fulfill this task:
Python:
import re
r = re.compile(r"(?:channel:)? ?<#(?P<channel>d+)>
+(?:as: ?(?P<as>.+)
+)?(:?image: ?(?P<image>.+)
+)?content:
*(?P<content>[sS]+)")
JS:
let r = /(?:channel:)? ?<#(?<channel>d+)>
+(?:as: ?(?<as>.+)
+)?(?:image: ?(?<image>.+)
+)?content:
*(?<content>[sS]+)/;
What I tried:
Testing regexes in regexr and pythex. Both work fine for me.
Then I entered them into Zapier:
output from the python code:
groups: null
id: <ID>
runtime_meta:
memory_used_mb: 57
duration_ms: 3
logs:
1. re.compile('(?:channel:)? ?<#(?P<channel>\d+)>\n+(?:as: ?(?P<nick>.+)\n+)?(:?image: ?(?P<image>.+)\n+)?content:\n*(?P<content>[\s\S]+)')
2. 'channel: <#1234567890123456>
as: bot nickname
content:
Hello, world!'
3. None
(and later in the Run JavaScript with similar result)
What works (somewhat):
When trying to debug it i removed image
part of the regexp (in the Text->Extract expression):
(?:channel:)? ?<#(?P<channel>d+)>
+(?:as: ?(?P<as>.+)
+)?content:
*(?P<content>[sS]+)
With the input:
channel: <#1234567890123456>
as: INFO
content:
Hello, world!
And the result was as expected:
output:
0: 1234567890123456
1: INFO
2: Hello, world!
_end: 68
_matched: true
_start: 0
as: INFO
channel: 1234567890123456
content: Hello, world!
Any help with getting it to work is appreciated :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…