Extract filenames from a string

Hello everyone!

I would like to get only the filenames “_GDP####” without the .jpg from the bellow json in a comma separated structure.

[
{
“pedido”: “1x Fotos impresas - 8 x 10 / Matte - _GDP8794.jpg 1x Fotos impresas - 6 x 8 / Matte - _GDP8793.jpg 1x Fotos impresas - 5 x 7 / Matte - _GDP8792.jpg 1x Foto en formato digital - _GDP8790.jpg”
}
]

I have tried with this regex and a set node .match(/(_GDP\d\d\d\d)/) but is only returning one value from the string.

Any help would be really appreciated.

The function below should do it:

const strings = items[0].json.pedido.split(" ");

let results = [];

for (const string of strings) {
    if (string.startsWith("_")) {
        results.push(string)
    }
}

results = results.map((s) => ({ json: { image:  s.replace(".jpg", "")}}))

return results
Example workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -240,
        180
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      \n\"pedido\": \"1x Fotos impresas - 8 x 10 / Matte - _GDP8794.jpg 1x Fotos impresas - 6 x 8 / Matte - _GDP8793.jpg 1x Fotos impresas - 5 x 7 / Matte - _GDP8792.jpg 1x Foto en formato digital - _GDP8790.jpg\"\n\n    }\n  }\n]\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        60,
        180
      ]
    },
    {
      "parameters": {
        "functionCode": "const strings = items[0].json.pedido.split(\" \");\n\nlet results = [];\n\nfor (const string of strings) {\n    if (string.startsWith(\"_\")) {\n        results.push(string)\n    }\n}\n\nresults = results.map((s) => ({ json: { image:  s.replace(\".jpg\", \"\")}}))\n\nreturn results"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        280,
        180
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thank you Ricardo. This worked flawlessly.

Great that it worked. Have fun.