regex to match all strings with # in them, but not # between strings
As the title says – I have some weird code I need to clean up from comments, which my program parses line by line. In each line There could be some text in our outside of quotes.
Each comment starts with a #, but I can’t just replace #.+$
with nothing, because if # happens inside a string, I would remove half of a string with all the code that comes after, despite it not being a comment.
So I want to catch and sanitize (through removal) all strings containing #