I have some text, including numbers of articles; I need to get an array of these numbers (including the article), after which there are "marker words". f.e. in text:
"123456/9902/001 one two three hand 123456/9902/002 fat got lot 123456/9902/003 five six 123456/9902/004 seven ten butter"
My resulting array for "marker words"= [hand,ten] will be:
["123456/9902/001 one two three hand","123456/9902/004 seven ten butter"]
My code finds something but it works wrong, what would the right regular expression be?
let markers = ["hand", "ten"],
fin = [];
let num = "(\\d{6}\/\\d{4}\/\\d{3}).*?";
markers.forEach(item => {
let reg = new RegExp(num + item, 'gmi');
found = text.match(reg);
found.forEach(item => fin.push(item));
if (result) {
console.log(`for ${item} : ${found.length}`);
console.log(found);
} else {
(console.log('Nothing'))
}
})
console.log(fin)