Skip to content

Commit 8028694

Browse files
authored
Update README.md
1 parent 75b55d8 commit 8028694

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# Python-Comments-Cleaner
22
These regex patterns are **better than most VS Code or VSCodium extensions** for removing comments, as they allow for more control and precision.
3+
4+
5+
6+
## 1. Full-Line Comments
7+
8+
### Regex Pattern:
9+
```regex
10+
^\s*#.*$
11+
```
12+
13+
### Description:
14+
Deletes entire lines that contain only comments, including those with leading spaces.
15+
16+
---
17+
18+
## 2. Trailing (Inline) Comments After Code
19+
20+
### Regex Pattern:
21+
```regex
22+
(?<=\S)\s{2,}#.*$
23+
```
24+
25+
### Description:
26+
Deletes comments that appear after code, but only if there are **at least two spaces** before the `#`.
27+
28+
---
29+
30+
## 3. Strict Docstring Matching (One-Liner)
31+
### Regex Pattern:
32+
```
33+
"""[^"]+"""
34+
```
35+
Description:
36+
Matches strict one-line docstrings enclosed by triple quotes (""") in function definitions. This ensures it doesn't accidentally match strings or comments.
37+
38+
---
39+
40+
## Usage in VS Code or VSCodium
41+
42+
1. **Open Find/Replace** (Ctrl+H)
43+
2. **Turn on Regex mode** (the `.*` button)
44+
3. **Paste the pattern in the "Find" field**
45+
4. **Leave "Replace" blank** (empty)
46+
5. **Click "Replace All"**

0 commit comments

Comments
 (0)