fork download
  1. import re
  2. rx = r"\b(?<!\w)((?:north|south)?(?:east|west)?)\b(?!\w)"
  3. s = "The westerly barn is a room. The field is east of the barn. The stable is northeast of the field. The forest is northwest of the field."
  4. print( re.findall(rx, s) )
Success #stdin #stdout 0.02s 9456KB
stdin
Standard input is empty
stdout
['east', 'northeast', 'northwest']