Article From:https://www.cnblogs.com/wangkun122/p/9970145.html

 

Match the city name, as long as the data after the first appearance

import re
a='The 6th floor of mirage building opposite Taigong Bus Township Company, Baiyun County, Bazhou District'
b=re.search(r'(^\w+?District |(^\ w+? County) |(^\ w+? Town)',a).group()
print(b)#bazhou district

 

Link of this Article: RE Regular Matching of City Names

Leave a Reply

Your email address will not be published. Required fields are marked *