Code

Remove Comments from Code

Removes comments from source, leaving anything that only looks like a comment inside a string alone.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the source you want the comments removed from.
  2. Choose whether to close the gaps or leave blank lines so line numbers stay put.
  3. Select Strip comments.
  4. 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.

Frequently asked questions

It should not, and the reason is the tokeniser. A search and replace for // deletes the middle of every URL in the file; this reads the source the way the language does, so a comment marker inside a string is left alone. Check the result before committing it all the same — nothing here has a compiler behind it.

Because they are the documentation the language itself exposes at runtime, and removing them changes what help() and most documentation tools produce. They are kept by default and removed if you ask, rather than silently disappearing.

Yes. Set the lines-left-behind option to preserve and each removed comment leaves its newlines in place, so every later line keeps the number it had. That is what you want when the output is going into a stack trace, a review or a diff.