make so it wont render the last data: while ((match = regex.exec(parsedText)) !== null)…
- User
make so it wont render the last data:
codewhile ((match = regex.exec(parsedText)) !== null) { parsedText = parsedText.replace(match[0], ''); newparsedText = parsedText.slice(0, match.index); const prisText = match[1].replace(/<[^>]*>?/gm, '').trim(); //find snippets in a string like eBay","snippets":["Philips HTS7140 Heimkinosysteme for sale online const snippets = match[1].match(/snippets\s*:\s*\[(.*?)\]/); const dashRegex = /^-+$/; // Check if prisText is neither “Pris” nor “—” if (prisText !== "Pris" && !dashRegex.test(prisText)) { new_products.push({ pris: match[1], källa: match[2] }); } }example text:
eBay","snippets":["Philips HTS7140 Heimkinosysteme for sale online
if it has the snippet in it then skip it
- Assistant
It looks like you want to skip over any matches where the string "snippets" appears within
match[1]. To do this, you can simply add a check that continues to the next iteration of the loop if "snippets" is found inmatch[1]. Additionally, ensuring thatmatch[1]exists before accessing it is important.Here's how you can modify your loop to skip over those matches:
javascript