fork download
  1. import re
  2.  
  3. text = '''Latitude (degrees): 4010.44 Longitude (degrees): 58.000 Radiation database: year month H(h)_m 2005 Jan 57.77 2005 Feb 77.76 2005 Mar 120.58 H(h)_m: Irradiation plane (kWh/m2/mo)'''
  4.  
  5. for match in re.finditer(r'(?P<key>\b[A-Z][ a-z_()]*): *(?P<value>.+?)(?=\b[A-Z][ a-z_()]*:|$)', text):
  6. # Key is the short pattern before ":" starting with a uppercase letter
  7. # Value must be the remaining, after the ": " and before the next key.
  8. print(match.group("key"), ":", match.group("value"))
Success #stdin #stdout 0.03s 9656KB
stdin
Standard input is empty
stdout
Latitude (degrees) : 4010.44 
Longitude (degrees) : 58.000 
Radiation database : year month H(h)_m 2005 Jan 57.77 2005 Feb 77.76 2005 Mar 120.58 
H(h)_m : Irradiation plane (kWh/m2/mo)