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

Thank you Ricardo. This worked flawlessly.

Great that it worked. Have fun.