Peter Pik Peter Pik - 9 months ago 58
Javascript Question

remove strong tag and its content from string

I'm having below string with this html, i'm wondering how can i remove/filter all strong tags and its text from the string?


2-3 spsk græsk yoghurt, gerne 10 %
<strong>Dressing: </strong>
1 lille spsk god mayonnaise
1-2 tsk æbleeddike
1-2 tsk honning
himalayasalt og friskkværnet hvid peber

so far i have this, but only seem to remove strong tag if it is at the top

var ingredientsArray = ingredients.split('<br>').map(it => it.trim()).filter(it => !!it && !it.startsWith('<strong>'));


You can use regex for this:

var ingredientsArray = ingredients.replace(/<strong>[\s\S]*?<\/strong>/g, '')
     .split('<br>').map(it => it.trim()).filter(Boolean);