Q:

Using regular expressions in python to extract location mentions in a sentence

I am writing a code using python to extract the name of a road,street, highway, for example a sentence like "There is an accident along Uhuru Highway", I want my code to be able to extract the name of the highway mentioned, I have written the code below.
sentence="there is an accident along uhuru highway"
listw=[word for word in sentence.lower().split()]
for i in range(len(listw)):
    if listw[i] == "highway":
        print listw[i-1] + " "+ listw[i]

I can achieve this but my code is not optimized, i am thinking of using regular expressions, any help please

A:

'uhuru highway' can be found as follows
import re

m = re.search(r'\S+ highway', sentence)  # non-white-space followed by ' highway'
print(m.group())
# 'uhuru highway'

