RosettaCodeData/Task/Strip-comments-from-a-string/Python/strip-comments-from-a-string-2.py

6 lines
115 B
Python
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
import re
m = re.match(r'^([^#]*)#(.*)$', line)
if m: # The line contains a hash / comment
line = m.group(1)