truncate post with gallery tag

Use strip_shortcodes as well. That should remove the shortcodes from the content.

A couple of notes: Your code seems to be doing some things that I don’t understand. For example, you run the the_content filter on your content which adds markup, only to run strip_tags later, which removes (at least some of) that markup. strip_tags will strip the <script> and <style> tags too, yet you have individual preg_replaces for those. Also, markup left by strip_tags, such as <p> tags, will count against your character limit. And, since you are breaking on a space you may end up breaking in the middle of a tag and end up with bad markup. This:

<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>

May end up being …

<p>Test paragraph.</p><!-- Comment --> <a

You might look into something like wp_filter_nohtml_kses, and certainly rethink how you deal with spaces and the broken markup that is bound to happen with this function.