fork download
  1. import re
  2. text = "23rd South 4th St."
  3. match = re.match(r'(?P<number>\d+)(?:th|[rn]d|st)?\s+(?P<street_name>.*?)\s+(?P<street_type>\S+)$', text)
  4. if match:
  5. print(match.groupdict())
Success #stdin #stdout 0.03s 9480KB
stdin
Standard input is empty
stdout
{'number': '23', 'street_name': 'South 4th', 'street_type': 'St.'}