【发布时间】:2018-08-10 04:30:26
【问题描述】:
我有不同格式的街道地址字符串。我试过这个旧的post,但没有多大帮助。我的字符串格式如下,
格式 1:
string_1 = ', landlord and tenant entered into a an agreement with respect to approximately 5,569 square feet of space in the building known as "the company" located at 788 e.7th street, st. louis, missouri 55605 ( capitalized terms used herein and not otherwise defined herein shall have the respective meanings given to them in the agreement); whereas, the term of the agreement expires on may 30, 2015;'
想要的输出:
788 e.7th street, st. louis, missouri 55605
格式 2:
string_2 = 'first floor 824 6th avenue, chicago, il where the office is located'
想要的输出:
824 6th avenue, chicago, il
格式 3:
string_3 = 'whose address is 90 south seventh street, suite 5400, dubuque, iowa, 55402.'
想要的输出:
90 south seventh street, suite 5400, dubuque, iowa, 55402
到目前为止,我试过了,这是string_1,
address_match_1 = re.findall(r'((\d*)\s+(\d{1,2})(th|nd|rd).*\s([a-z]))', string_1)
我得到一个空列表。
对于第二个字符串,我尝试了相同的方法并得到如下的空列表,
address_match_2 = re.findall(r'((\d*)\s+(\d{1,2})(th|nd|rd).*\s([a-z]))', string_2)
如何尝试使用 re 进行匹配?它们都是不同的格式,我怎样才能让套件参与string_3?任何帮助将不胜感激。
【问题讨论】:
标签: regex string python-3.5