. in a regular expression matches every character except \n . In some regex variants, you can add the s flag to match them, but not in Javascript.
Instead, you can use the character class [\s\S] , which matches all spaces and all without spaces, which is all. ? after * means that it will not be greedy, otherwise it will match between the first ALTER and the last GO .
str = str.replace(/ALTER[\s\S]*?GO/g, '');
jsFiddle .
source share