13 lines
395 B
Python
13 lines
395 B
Python
import re
|
||
text = '''
|
||
2024-03-15 天气:晴 温度:15-25°C
|
||
2024-03-16 天气:多云 温度:12-20°C
|
||
2024-03-17 天气:小雨 温度:10-18°C
|
||
'''
|
||
|
||
pattern = r'(\d{4}-\d{2}-\d{2})\s*天气:([^ ]+)\s*温度:(\d+)-(\d+)°C'
|
||
matches = re.findall(pattern, text)
|
||
|
||
for match in matches:
|
||
date, weather, low, high = match
|
||
print(f'{date}: {weather}, {low}°C-{high}°C') |