Filter Numbers from String

Hello, Im trying to filters numbers from a string node, like:

set:
name = 123123 - Alex

I want to create a VAR or other String with only numbers from ‘name’
name-numbers = 123123

It’s possible?

Hey @Alexandre_Magno!

This is possible using Regex.

The following workflow illustrates this. The Regex that I am using may not cover all the use-case. You can use Regex101 to build these Regex and use them in the workflow.

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "Name",
              "value": "12341234 - Alex"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "name-numbers",
              "value": "={{$json[\"Name\"].replace(/ - [a-zA-Z]*/,'')}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        700,
        300
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

The more generic version, which simply returns the first number found, would be:

{{ $json["Name"].match(/\d+/g)[0] }}