We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8ee06e7 commit 7e56220Copy full SHA for 7e56220
parse.py
@@ -1,4 +1,20 @@
1
-def remove_comments(code: str) -> str:
+import re
2
+
3
+def remove_comments(input_string):
4
+ # Regular expression pattern to match /* ... */ style comments
5
+ pattern = r'/\*.*?\*/'
6
+ cleaned_string = re.sub(pattern, '', input_string, flags=re.DOTALL)
7
8
+ # Remove single-line comments (//) by splitting lines and keeping only non-comment parts
9
+ lines = cleaned_string.split('\n')
10
+ filtered_lines = []
11
+ for line in lines:
12
+ line = line.split('//')[0] # Remove everything after // in the line
13
+ filtered_lines.append(line.strip())
14
15
+ return ''.join(filtered_lines)
16
17
+def _remove_comments_old(code: str) -> str:
18
lines = code.splitlines()
19
no_comm = ''
20
in_comment = False
0 commit comments