Replace a custom Tag with a Partial
===

I have been trying to replace a custom tag I have in a selection of HTML with a partial.

In my HTML I have [gallery 2] (2 being the ID of the gallery) 

I have been trying to work out a way to find the [gallery 2] and replace it with the output of the partial gallery passing the ID of 2 through to the gallery partial so that it loads the correct images. 

Does anyone have any idea how I might be able to do this? I have thought about using a simple string replace, however I am not sure how to call the output of the partial to replace the custom [gallery 2] tag in my HTML. 

Thanks in advance, 