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

6 lines
115 B
Python

import re
m = re.match(r'^([^#]*)#(.*)$', line)
if m: # The line contains a hash / comment
line = m.group(1)