Чего мне здесь не хватает?
import re sample = 'this is an example' p = re.compile('this is\b\w+\bexample') p.findall(sample) []
Разве шаблон не должен совпадать? \b\w+\b должно соответствовать space + an + space или нет?
\b\w+\b
space + an + space
Поскольку ни \b, ни \w не соответствуют пробелам.
\b
\w
import re sample = "this is an example" r = re.findall(r"this is\s+\w+\s+example", sample) print(r)
См. это демо .