Faster Union
Знаток
(251)
1 день назад
import re
text = "Some words contain the word cat: scat, ducati, alcatel, catalyst, worldcat and of course cat!"
patterns = [r"\bcat", r"cat\b", r"\bcat\b", r"\Bcat", r"cat\B", r"\Bcat\B"]
matches = [len(re.findall(pattern, text)) for pattern in patterns]
print(matches)