Assuming the text on the left cannot contain opening parenthesis, splitting by the first opening parenthesis might work as well:
>>> clean_title = 'Alone in the Dark (The Cincinnati Series Book 2)'
>>> clean_title.split('(', 1)[0].lower().rstrip()
'alone in the dark'
Note that it will not fail even if there are no parenthesis:
>>> clean_title = 'Test'
>>> clean_title.split('(', 1)[0].lower().rstrip()
'test'
As far as the regular expression approach, you might also use re.sub()
which would not require checking if there is a match or not. And, as a bonus, let's account for the extra space before the parenthesis:
>>> re.sub(r"(.*?)\s?\(.*?\)", r"\1", clean_title).lower()
'alone in the dark'
Or:
>>> re.sub(r"\s?\(.*?\)", r"", clean_title).lower()
'alone in the dark'
You can also do the lowering part in a replacement function:
>>> re.sub(r"(.*?)\s?\(.*?\)", lambda m: m.group(1).lower(), clean_title)
'alone in the dark'
Also note that I'm using non-greedy regular expressions.