假设我有一个长字符串,其地址数据格式为:
string = ... 'Something 3; Place: Something; City: NewYork; Street: Broadway; House: 7; Lat g: 33,105438; Long g: 12,749558; Object: Something;'...
我想从以下字符串中提取子字符串 Place: 到 Long g: 12,749558. 使用正则表达式findall()。 有人能帮帮我吗?谢谢!
Place:
Long g: 12,749558.
我想从我的字符串中获取:
Place: Something; City: NewYork; Street: Broadway; House: 7; Lat g: 33,105438; Long g: 12,749558;
您可以使用以下正则表达式模式: r'Place:.*?Long g: \d+,\d+;' .
r'Place:.*?Long g: \d+,\d+;'
import re string = '... Something 3; Place: Something; City: NewYork; Street: Broadway; House: 7; Lat g: 33,105438; Long g: 12,749558; Object: Something;...' pattern = r'Place:.*?Long g: \d+,\d+;' result = re.findall(pattern, string) # "Place: Something; City: NewYork; Street: Broadway; House: 7; Lat g: 33,105438; Long g: 12,749558;"