As the other responders said, you can use a RegExp constructor for that. But while you're at it, you should get rid of that (.*). Assuming it's meant to consume whatever other attributes the <div> has, you'll be better off using [^<>]*. That will confine the match to one element at a time; (.*) is the ultimate escape artist.
But I'm curious: are you really passing in strings like <div id="container_gallery_", including the first part of the HTML element? Or are you only passing a replacement for the attribute's value, (e.g. container_gallery_)? If that's the case, this regex should serve you better:
var regex = new RegExp('<div\s+"` + (your var) + '"[^<>]*></div>', 'gi' );
I'm assuming the `id` attribute is always in the first position which generally not a safe assumption, but it makes the regex a lot easier, both to write and to read. ;)
And don't forget to check the passed-in string for characters that are illegal in an HTML attribute.