Removing headers from blog post "excerpts" (using Hacksaw) I'm using hacksaw to display the first part of my article on a blog listing page.

{{ entry.body|hacksaw(chars='300',allow='&lt;p&gt;', append='...') }}


The issue I have is when an article starts with a heading in it's body it looks like the attached. I'd ideally like to remove any headings from the excerpts.

 



As you can see the headings 'Reducing the size...' and 'Scaling' come through as plain text and the rest continues with my allowed 

The only way I can think to do this is to allow their headings (h2 and h3) and then hide them in CSS, but I'm hoping there's a better way.
You could use the Twig replace filter with a regular expression, this'll remove the tag and it's content.

{{ entry.body | replace('/&lt;h([1-6])&gt;.*?&lt;\\/h([1-6])&gt;/', '') | raw | hacksaw(chars='300',allow='&lt;p&gt;', append='...') }} 


The only limitation is regular expressions aren't fantastic with nested html tags, so your mileage my vary!

You might need to play around with the Regex a bit if you want to just limit it to a few headings, this will strip all h1, h2, h3, h4, h5, h6. You also might not need the | raw filter, it seemed to escape everything after the replace when I quickly tested it.