re.findall()
with the supplied pattern
to find all matching substrings.import re def words(s, pattern = '[a-zA-Z-]+'): return re.findall(pattern, s)
words('I love Python!!') # ['I', 'love', 'Python'] words('python, javaScript & coffee') # ['python', 'javaScript', 'coffee'] words('build -q --out one-item', r'\b[a-zA-Z-]+\b') # ['build', 'q', 'out', 'one-item']
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️