Remove Comments from Code
Removes comments from source, leaving anything that only looks like a comment inside a string alone.
Loading the tool…
How to use this tool
- Paste the source you want the comments removed from.
- Choose whether to close the gaps or leave blank lines so line numbers stay put.
- Select Strip comments.
- Check the summary for any comment that was never closed, which usually means the file was truncated.
What comment stripper does
The reason to do this with a tokeniser rather than a search and replace is that a search and replace destroys code. A regular expression for // deletes half of every URL in the file; one for /* corrupts anything containing that sequence in a string. This reads the source the way the language does, so only real comments are removed.
You can keep line numbers by leaving the removed comments as blank lines, which is what you want if the output is going back into a stack trace or a review, or close the gaps for a compact result. Python docstrings are kept by default, because a docstring is documentation the interpreter can read and deleting it silently would be a surprise.