fork download
  1. import re
  2.  
  3. pattern = r"^\W*(?P<title>\w.*?) [–-] located in (?P<city>\w.*?), (?P<state>\w.*)"
  4.  
  5. wiki = """There are several Buddhist universities in the United States. Some of these have existed for decades and are accredited. Others are relatively new and are either in the process of being accredited or else have no formal accreditation. The list includes:
  6. • Dhammakaya Open University – located in Azusa, California,
  7. • Dharmakirti College – located in Tucson, Arizona
  8. • Dharma Realm Buddhist University – located in Ukiah, California
  9. • Ewam Buddhist Institute – located in Arlee, Montana
  10. • Naropa University - located in Boulder, Colorado
  11. • Institute of Buddhist Studies – located in Berkeley, California
  12. • Maitripa College – located in Portland, Oregon
  13. • Soka University of America – located in Aliso Viejo, California
  14. • University of the West – located in Rosemead, California
  15. • Won Institute of Graduate Studies – located in Glenside, Pennsylvania"""
  16.  
  17. for item in re.finditer(pattern, wiki, re.M):
  18. print(item.groupdict())
Success #stdin #stdout 0.03s 9904KB
stdin
Standard input is empty
stdout
{'title': 'Dhammakaya Open University', 'city': 'Azusa', 'state': 'California,'}
{'title': 'Dharmakirti College', 'city': 'Tucson', 'state': 'Arizona'}
{'title': 'Dharma Realm Buddhist University', 'city': 'Ukiah', 'state': 'California'}
{'title': 'Ewam Buddhist Institute', 'city': 'Arlee', 'state': 'Montana'}
{'title': 'Naropa University', 'city': 'Boulder', 'state': 'Colorado'}
{'title': 'Institute of Buddhist Studies', 'city': 'Berkeley', 'state': 'California'}
{'title': 'Maitripa College', 'city': 'Portland', 'state': 'Oregon'}
{'title': 'Soka University of America', 'city': 'Aliso Viejo', 'state': 'California'}
{'title': 'University of the West', 'city': 'Rosemead', 'state': 'California'}
{'title': 'Won Institute of Graduate Studies', 'city': 'Glenside', 'state': 'Pennsylvania'}