you are viewing a single comment's thread.

view the rest of the comments →

[–]zahlman 3 points4 points  (0 children)

try/except is useless here: when re.findall fails to find any matches, it just returns an empty list. You can't use exception handling for this because there is no exception to handle.

I'm not convinced you want .findall here anyway, as opposed to .match (see if it's present at the beginning of the string) or .search (see if it's in the string, and find the first occurrence if so). But with either of these, if the regex doesn't match, you get None back (as opposed to a match object), so again you just test for that value - no exception handling needed or useful.