var s = "str0\nstr1\n/*\nstr2\nstr3\nstr4\n*/\nstr5\nstr6"; s = s.replace( /\/\*[\S\s]*\*\//g, function( ss ) { return ss.replace( /(.+)/g, "[c]$1[/c]" ); } ); alert( s );