I am trying to extract a part of a string for each element in the array.
I have managed to get all files ending with .pdf, but I don't know how to do the extraction part.
I would assume that I need to use a regular expression to do this job, however, I am not sure where to start with that.
Given the first element ./pdf/main/test1.pdf
, I want to return /test1.pdf
.
Follow my code below:
glob('./pdf/main/*.pdf', {}, (err, files) => {
console.log(files) // ['./pdf/main/test1.pdf','./pdf/main/test2.pdf' ]
files.map(f => {
// Here I want to extract and return the following output:
// /test1.pdf
// /test2.pdf
})
})