Nuke comments until no match left: /\*[ -~\n]+?\*/|//[^\n]* then do: \n *\n+ replace into \n until no match left (4 spaces) replace into \t