0

I need help to extract the codes from a pdf file that has been converted into a json object. Is it possible to create new array with only fs codes like this FS0003918245, FS0003940457, FS0003898043. From the existing one make a new one with fs codes only. thank you

let array = ["FS0003918245", "FS0003940457", "FS0003898043"]

let array = [
  [
    "1.         FS0003918245\nBr. paketa: 1\nPovrat pošiljke - DS\nFS0003918245",
    null,
    "Primalac\nNaziv: Ljubica Čeman\nAdresa: Despota Stefana 2, 8 sprat Mesto: 21000 Novi Sad\nTelefon: 38163488007",
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "Otkupnina:\nVrednost: Plaćanje: Cena:",
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "10.000,00\n0,00\nNalogodavac Virman 210,00",
    null,
  ],
  [
    "Referenca: 1764801 ; MOZE KURIR DA OSTAVI PAKET U PRODAVNICU GAZDARICI SASKI",
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
  ],
  [
    "2.         FS0003940457\nBr. paketa: 1\nPovrat pošiljke - DS\nFS0003940457",
    null,
    "Primalac\nNaziv: Marija STANKOVIC Adresa: Dedobarski put bb Mesto: 16220 Grdelica\nTelefon: 381637775928",
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "Otkupnina: Vrednost: Plaćanje: Cena:",
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "7.000,00\n0,00\nNalogodavac Virman 210,00",
    null,
  ],
  [
    "Referenca: 1791153 ; Nazvati 1h prije isporuke",
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
  ],
  [
    "3.         FS0003898043\nBr. paketa: 1\nPovrat pošiljke - DS\nFS0003898043",
    null,
    "Primalac\nNaziv: Dusan glisis Adresa: Olge Penavin 8 Mesto: 21000 Novi Sad Telefon: 381606369616",
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "Otkupnina: Vrednost: Plaćanje: Cena:",
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "8.000,00\n0,00\nNalogodavac Virman 210,00",
    null,
  ]
];
1
  • 2
    please do not post real names/addresses/phones here Commented Jan 8, 2023 at 11:06

1 Answer 1

2

You can simply use this code:

const regex = /FS\d{10}/g
const result = array.map(innerArray => {
    return innerArray.filter(f => regex.test(f)).map(m=>{
        return m.match(regex)
    })
}).flat(Infinity)

Or this one what do the same:

const regex = /FS\d{10}/g
const result = array.map(innerArray => {
    return innerArray.map(m => {
        return m?.match(regex)
    })
}).flat(Infinity).filter(Boolean)

Or to avoid duplicates you can also add:

const resultWithoutDuplicates = [...new Set(result)]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.