Anyone know regex when using "replace" to remove all br tags at start and end of tags:

So <foo><br>Foo<br></foo> or <foo><br>Foo</foo> etc. becomes <foo>Foo</foo>

And entire instances of:

<foo><br></foo> or <foo><br><br></foo> etc. is all removed completely

^ Any number of <br>s, plus ignoring whitespace, plus accounting for <br/> and <br />?!

  • I've actually gone with: {{ block.text|replace({'<br>': '', '<br/>': '', '<br />': ''})|replace('/<[^\\/>][^>]*><\\/[^>]+>/', '')|raw }} for now ...
    – KevAdamson
    Mar 17 '21 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.