Yes, I use regex in my apps too. But only for simple string patterns. Something like multi line codes is out of my capacity. That's why I went for loops.
Sorry about being facetious - I actually will help when I can get to my PC so I can test any code I suggest. Currently existing on my Andoid tablet whilst on holiday. Another week or so before we head for home.
Size reduction, certainly. When you have a code module, it takes up room twice. Once for the text form of the code, once for the compiled pseudo-code that is kept in a BLOB (Binary Large OBject). If you removed "debug.print" and replaced each instance with the single quote mark, that is 10 bytes per replacement. With 5000 of them in a single project, that would probably account for at least 50 Kb for the text and an unknown amount for the compiled code. I'd say that was a good size reduction.