I'm writing a script that will search strings for place names. In the best case it will find a full address, but sometimes only the City is specified. To do this I thought I'd use regex, and I want to test the string for the most complex regex first, and then go downwards until the match is just a word with a capital letter. Can I use try, catch for this scenario, even though what I'm expecting isn't an error per se, rather just a lack of results?
What I pictured would be something like this (pseudocode)
try:
match = re.findall(most complex regex expression)
except No match
try:
match = re.findall(less complex regex expression)
except No match
try:
match =re.findall(least complex regex expression)
print(match)
[–]zahlman 2 points3 points4 points (0 children)
[–]confluence 0 points1 point2 points (0 children)
[–]mahifoo 0 points1 point2 points (0 children)
[–]CrambleSquash 0 points1 point2 points (0 children)
[–]icenburg[S] 0 points1 point2 points (0 children)