These regex patterns are better than most VS Code or VSCodium extensions for removing comments, as they allow for more control and precision.
^\s*#.*$
Deletes entire lines that contain only comments, including those with leading spaces.
(?<=\S)\s{2,}#.*$
Deletes comments that appear after code, but only if there are at least two spaces before the #
.
"""[^"]+"""
Description: Matches strict one-line docstrings enclosed by triple quotes (""") in function definitions. This ensures it doesn't accidentally match strings or comments.
- Open Find/Replace (Ctrl+H)
- Turn on Regex mode (the
.*
button) - Paste the pattern in the "Find" field
- Leave "Replace" blank (empty)
- Click "Replace All"