How to remove comments from a Julia file?

Rather than using regexes, you might consider simply using Julia’s parser, which gives you a syntax tree that you can walk to output anything you want. This will be a lot more robust than processing code as strings.