Find matching patterns in text with Python