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

2018-06-22 20:57:24 +00:00
import re
2013-04-11 01:07:29 -07:00
2018-06-22 20:57:24 +00:00
m = re.match(r'^([^#]*)#(.*)$', line)
if m: # The line contains a hash / comment
line = m.group(1)