https://github.com/theholyonez/python-comments-cleaner
These regex patterns are **better than most VS Code or VSCodium extensions** for removing comments, as they allow for more control and precision.
https://github.com/theholyonez/python-comments-cleaner
clean-code extension python python-clean-code regex regex-pattern
Last synced: 8 months ago
JSON representation
These regex patterns are **better than most VS Code or VSCodium extensions** for removing comments, as they allow for more control and precision.
- Host: GitHub
- URL: https://github.com/theholyonez/python-comments-cleaner
- Owner: TheHolyOneZ
- License: mit
- Created: 2025-04-28T22:22:02.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-04-28T22:23:48.000Z (8 months ago)
- Last Synced: 2025-04-30T05:04:36.291Z (8 months ago)
- Topics: clean-code, extension, python, python-clean-code, regex, regex-pattern
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python-Comments-Cleaner
These regex patterns are **better than most VS Code or VSCodium extensions** for removing comments, as they allow for more control and precision.
## 1. Full-Line Comments
### Regex Pattern:
```regex
^\s*#.*$
```
### Description:
Deletes entire lines that contain only comments, including those with leading spaces.
---
## 2. Trailing (Inline) Comments After Code
### Regex Pattern:
```regex
(?<=\S)\s{2,}#.*$
```
### Description:
Deletes comments that appear after code, but only if there are **at least two spaces** before the `#`.
---
## 3. Strict Docstring Matching (One-Liner)
### Regex Pattern:
```
"""[^"]+"""
```
Description:
Matches strict one-line docstrings enclosed by triple quotes (""") in function definitions. This ensures it doesn't accidentally match strings or comments.
---
## Usage in VS Code or VSCodium
1. **Open Find/Replace** (Ctrl+H)
2. **Turn on Regex mode** (the `.*` button)
3. **Paste the pattern in the "Find" field**
4. **Leave "Replace" blank** (empty)
5. **Click "Replace All"**