Basically I need to remove the gallery shortcode from the WordPress content, I’m using
echo preg_replace('/]+]/', '', get_the_content() );
It is removing the gallery shortcode successfully, but also the paragraph tags which I need to keep. The idea is that I want to output everything in the content except the gallery.
You could use WordPress strip_shortcode function.
Look at the example in the Codex.
You can create a filter that strips shortcodes:
and call it when you need (in your template):
EDIT 1
Another way to get that (and answering you comment) you can use WordPress apply_filters function in the content after remove the undesirables shortcodes.
But I would not recommend to you to do that. I think forcing your site to modify the content of a post could make that hard to understanding. Maybe you should work with WordPress Excerpt and avoid any problem.
A link that helped me
to remove a shortcode or a particular list of shortcode you can use this code.
Accepts single, comma seprated shortcode string or array of shortcodes.