Remove Comments

Remove comments from up to 100,000 lines without breaking strings, URLs or regular expressions. It runs in your browser, so nothing is uploaded.

Settings Cleaned
Line comment
Escape character
Block comment
Preset:

The cleaned code replaces your input in this box. Keep a copy of the original if you want to compare them.

How to use it

  1. Pick the preset for your language. It sets the comment markers and how strings are read.
  2. Paste your code and click Remove comments.
  3. Review the result, then click Copy.
  4. To see exactly what was removed, put the original and the result in Compare Codes.

Which preset to use

C-like
C, C++, C#, Java, JavaScript, TypeScript, Go, Rust, Swift, Kotlin, Dart and PHP.
Python
Python. Triple quoted strings and docstrings are kept.
HTML
HTML, XML and comments in Markdown.
CSS
CSS. For SCSS and Less, set the line comment to //.
SQL
Most dialects. For MySQL # comments, change the line comment.
MATLAB and Ruby
Including %{ %} and =begin =end blocks.

For other languages, start from the closest preset and edit the markers. The comment syntax reference lists them.

What it handles

  • Comment markers inside strings, template literals, C# verbatim and raw strings, Java text blocks and JavaScript regular expressions are left alone.
  • Lines that held only a comment are removed, and trailing spaces are trimmed.
  • Not supported: nested block comments, heredocs, and # in the middle of a word in shell scripts. Edge cases with test snippets
  • Some comments should stay, such as license headers and linter directives. Which comments to keep