I need to read in lines from a text file, basically everything after and including the first open parenthesis can be removed with an empty string. I came up with a regex:
>>> line = "Bar Harbor (College of the Atlantic)"
>>> re.sub(r"(.*) ?\(.*$","\1", line)
'\x01'
The following works, but excludes lines that do not have parentheses which is not according the specs (so it does not work)
match = re.match("(.*?) ?\(.*$",line)
if match:
towns.append(match.group(1))
What am i doing wrong in te first substitute? Regexs are not necessary, I just need to remove everything after the first parentheses, so also if there is more than one way I'm also interested.