select regexp_replace('here is [[my text]] to replace and [[some more]]',
E'\\[\\[(.*?)\\]\\]',
replace(E'\\1', ' ', '_'),
'g'
);
Side note, you seldom want to use “E” (escape) string literals with regexes (or in general really) using just the simple literal syntax removes the need for double-backslashing.
David J.