Skip to main content
Programming Language Tools

Code Comment Remover

Strip common single-line and block comments from code in several languages - pattern-based, not a full language parser.

Paste your code and choose its language style - this tool strips out single-line and block comments using that language's comment syntax.

This uses pattern matching, not a full language parser - it can occasionally misidentify a comment-like sequence inside a string literal. Review the output before relying on it for anything critical.

Regex/pattern-based comment removal cannot perfectly parse every edge case (like a comment marker inside a string literal) - always review the output before relying on it.

What Does This Tool Do?

It removes comments matching common patterns for a chosen language style - // and /* */ for JavaScript/PHP/CSS-style languages, # for Python/shell-style languages, and -- for SQL.

Why Use This Tool?

Useful for quickly stripping comments from a code snippet before sharing or minifying it, when a full language-specific tool isn't necessary.

How to Use It

  1. Paste your code.
  2. Choose the comment style matching your language.
  3. Copy the comment-stripped result.

Important Notes

This uses pattern matching, not a full language parser - a comment-marker character appearing inside a string literal (e.g. a URL containing //) can be incorrectly treated as a comment start. Always review the output before using it.

Example

// calculate the order total
function total(items) {
    /* prices are in paise */
    return items.reduce((s, i) => s + i.price, 0); // sum
}

becomes:

function total(items) {

    return items.reduce((s, i) => s + i.price, 0);
}

Lines that held only a comment are left empty, so the code keeps its line structure; remove the blank lines afterwards if you want it compact.

Good Reasons to Strip Comments

  • Sharing a snippet publicly without internal notes, ticket numbers or names.
  • Pasting code into a question or an AI prompt where comments add noise.
  • Comparing two versions of a file when only the code matters.
  • Reducing the size of a script for an embed when no build tool is available.

Check These After Removing

  • URLs in strings such as "https://example.com" - the // can be mistaken for a comment.
  • Licence headers that must legally stay in distributed code.
  • Special comments that tools rely on: /*! preserve */, // @ts-ignore, # type: ignore, #!/usr/bin/env python shebang lines.
  • CSS hacks or conditional comments in older HTML emails.

To shrink code further, use the Code Minifier; to count what remains, use the Code Line Counter.

Frequently Asked Questions

It is pattern-based, not a full parser, so comment-like text inside strings (such as "http://" or "#hash") can occasionally be affected. Review the output before using it.

To share or publish code without internal notes, or to reduce size. For production JavaScript and CSS, a minifier does this automatically.

No. Comments are removed in your browser, so your source code never leaves your device.
Share this tool: