E.g. I have this string
-- This -- is -- one -- another -- comment --
I want the matched elements to be
\"This\", \"is\", \"one\", \"another\", and \"comment\"
To read all I would use positive look achead:
const data = '-- This -- is -- one -- another -- comment --'
const readAll = data => {
const regex =/--\s*(.*?)\s*(?=--)/g
const found = []
let temp
while (temp = regex.exec(data)) {
found.push(temp[1])
}
return found
}
console.log(readAll(data))
And to remove comments just do this:
const data = `-- This -- is -- one -- another -- comment -- this is not a comment`.replace(/--.*--/g, '')
console.log(data)