When I try your idea, I have this error x, y, width, height = re.findall(pattern, str)[0] IndexError: list index out of range How can I use findall to handle error case? i.e. what if there is no match? how can I handle it gracefully?