Valid regex expression not working in set mode

Hello, I’m in the process of creating a workflow with the N8N desktop app (on a Macbook Air M1), and I’m trying to use the “set” node to extract URL’s from a string, but it’s not working, even though the regex expression is valid, as you can see in this screenshot:

Here’s the code for the node:

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "Channel name",
              "value": "={{$node[\"YouTube1\"].json[\"snippet\"][\"title\"]}}"
            },
            {
              "name": "description",
              "value": "={{$node[\"YouTube1\"].json[\"snippet\"][\"description\"]}}"
            },
            {
              "name": "Country",
              "value": "={{$node[\"YouTube1\"].json[\"brandingSettings\"][\"channel\"][\"country\"]}}"
            },
            {
              "name": "Language",
              "value": "={{$node[\"YouTube1\"].json[\"brandingSettings\"][\"channel\"][\"defaultLanguage\"]}}"
            },
            {
              "name": "Links",
              "value": "={{$node[\"YouTube1\"].json[\"snippet\"][\"description\"].match([(http(s)?):\\/\\/(www\\.)[email protected]:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([[email protected]:%_\\+.~#?&//=]*))}}"
            }
          ],
          "number": [
            {
              "name": "Video count",
              "value": "={{$node[\"YouTube1\"].json[\"statistics\"][\"videoCount\"]}}"
            },
            {
              "name": "Video views",
              "value": "={{$node[\"YouTube1\"].json[\"statistics\"][\"viewCount\"]}}"
            },
            {
              "name": "Subscribers",
              "value": "={{$node[\"YouTube1\"].json[\"statistics\"][\"subscriberCount\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        670.5361445783133,
        41.30722891566268
      ]
    }
  ],
  "connections": {}
}

I know that the expression is valid, as it’s working in this “IF” node:

{
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"YouTube3\"].json[\"snippet\"][\"description\"]}}",
              "operation": "regex",
              "value2": "[\\w\\.-][email protected][\\w\\.-]+"
            },
            {
              "value1": "={{$node[\"YouTube3\"].json[\"snippet\"][\"description\"]}}",
              "operation": "regex",
              "value2": "[(http(s)?):\\/\\/(www\\.)[email protected]:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([[email protected]:%_\\+.~#?&//=]*)"
            }
          ]
        },
        "combineOperation": "any"
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1410,
        440
      ]
    }
  ],
  "connections": {}
} 

Any ideas of why this is happening and how to fix it? Thanks!

So I think this might be a problem with the syntax of .match(). To specify a regular expression you’d need to wrap it in slashes (like /yourRegularExpressionGoesHere/) and then append any modifiers after the last slash (like /yourRegularExpressionGoesHere/i.

So I think your expression would need to look like this:

{{$node["YouTube1"].json["snippet"]["description"].match(/[(http(s)?):\/\/(www\.)[email protected]:%._\+~#=]{2,256}\.[a-z]{2,6}\b([[email protected]:%_\+.~#?&//=]*)/)}}

Hi, thanks! The expression is now valid, but somehow, but it doesn’t return any values, which is weird as matches are found using the same Regex in the node IF.