I am searching for city names in a string:
mystring = 'SDM\Austin'
city_search = r'(SD|Austin)'
mo_city = re.search(city_search,mystring,re.IGNORECASE)
city = mo_city.group(1)
print(city)
This will return city as 'SD'.
Is there a way to make 'Austin' the preference?
Switching the order to (Austin|SD) doesn't work.
The answer is the same as How can I find all matches to a regular expression in Python?, but the use case is a little different since one match is preferred.