Прямо сейчас я делаю это: < /p>
Код: Выделить всё
def get_location(s):
s = s.strip(STRIP_CHARS)
keywords = "at|outside|near"
location_pattern = "(?P((?P{keywords}\s[A-Za-z]+)))".format(keywords = keywords)
location_regex = re.compile(location_pattern, re.IGNORECASE | re.MULTILINE | re.UNICODE | re.DOTALL | re.VERBOSE)
for match in location_regex.finditer(s):
match_str = match.group(0)
indices = match.span(0)
print ("Match", match)
match_str = match.group(0)
indices = match.span(0)
print (match_str)
get_location("Im at building 3")
< /code>
У меня есть три проблемы: < /p>
[list]
[*] Это дает только "AT" как вывод, но также должно дать здание. < /li>
captures = match.capturesdict()
[/list]
Подробнее здесь: https://stackoverflow.com/questions/467 ... sing-regex