Python regex AttributeError: ‘NoneType’ object has no attribute ‘group’

I managed to figure out this solution: omit group() for the situation where the searchbox reply is "No results" and thus doesn’t match the Regex.

try:
    searchbox_result = re.match("^.*(?=(\())", searchbox).group()
except AttributeError:
    searchbox_result = re.match("^.*(?=(\())", searchbox)

Leave a Comment

tech