У меня есть следующая строка:
Быстрая коричневая лиса, кошка в (шляпе) и собака в фунте. Кот в THE (шапка):
Мне нужна помощь в извлечении следующего текста:
1) кот в (шапке)
2) Кот в ТЕ (шапка)
Я пробовал следующее:
p1 = """The quick brown fox, the cat in the (hat) and the dog in the pound. The Cat in THE (hat)"""
pattern = r'\b{var}\b'.format(var = p1)
with io.open(os.path.join(directory,file), 'r', encoding='utf-8') as textfile:
for line in textfile:
result = re.findall(pattern, line)
print (result)